Red Hat Bugzilla – Bug 800585
CVE-2012-1129 freetype: heap off-by-one buffer underflow in Type42 parser t42_parse_sfnts() (#35602)
Last modified: 2016-11-08 11:21:10 EST
An out-of heap-based buffer read flaw was found in the way Type42 font parser of the FreeType font rendering engine performed parsing of certain special font name table (SFNT) strings. A remote attacker could provide a specially-crafted font file, which once opened in an application linked against FreeType would lead to that application crash.
Upstream bug report:
Added CVE as per http://www.openwall.com/lists/oss-security/2012/03/06/16
This issue affects the versions of the freetype package, as shipped with Red Hat Enterprise Linux 5 and 6.
This issue affects the versions of the freetype package, as shipped with Fedora release of 15 and 16.
This bug is not a security problem. Affected code is the following code from src/type42/t42parse.c :
610 /* A string can have a trailing zero byte for padding. Ignore it. */
611 if ( string_buf[string_size - 1] == 0 && ( string_size % 2 == 1 ) )
Here problem occurs when string_size == 0. In that case string_buf[string_size - 1] reads one byte right before the beginning of the heap-based string_buf buffer. Such one byte buffer underflow can only lead to program crash when string_buf starts at the memory page boundary and the previous page is not mapped. However, that can not happen with the current glibc malloc() implementation. A memory address returned to a program by malloc() function has additional malloc header located right before it. Hence string_buf[string_size - 1] reads part of that header and can not access unmapped memory.
This bug can be detected by memory usage checkers as valgrind or AddressSanitizer, but does not lead to crash during the normal use.
The value read from the malloc header has no impact on whether the "if" expression is evaluated as true or falls. The second part of the "if" expression is: ( string_size % 2 == 1 ) which evaluates to false when string_size == 0. Hence string_size is not decremented and remains 0.
The code immediately following is:
614 if ( !string_size )
616 FT_ERROR(( "t42_parse_sfnts: invalid string\n" ));
617 error = T42_Err_Invalid_File_Format;
618 goto Fail;
which causes the font file to be rejected as invalid.
This bug is not a security issue. For detailed explanation, refer to: https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2012-1129#c5