Bug 800585 (CVE-2012-1129)

Summary: CVE-2012-1129 freetype: heap off-by-one buffer underflow in Type42 parser t42_parse_sfnts() (#35602)
Product: [Other] Security Response Reporter: Jan Lieskovsky <jlieskov>
Component: vulnerabilityAssignee: Red Hat Product Security <security-response-team>
Status: CLOSED NOTABUG QA Contact:
Severity: low Docs Contact:
Priority: low    
Version: unspecifiedCC: behdad, fonts-bugs, jrusnack, kevin, mkasik
Target Milestone: ---Keywords: Security
Target Release: ---   
Hardware: All   
OS: Linux   
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-03-15 12:28:18 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Bug Depends On:    
Bug Blocks: 800639    

Description Jan Lieskovsky 2012-03-06 18:48:09 UTC
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:
[1] https://savannah.nongnu.org/bugs/?35602

Upstream patch:
[2] http://git.savannah.gnu.org/cgit/freetype/freetype2.git/commit/?id=82365c0dead99dd119d9e7117cf4f36ce1d1cbe1

Comment 1 Kurt Seifried 2012-03-06 20:48:49 UTC
Added CVE as per http://www.openwall.com/lists/oss-security/2012/03/06/16

Comment 2 Jan Lieskovsky 2012-03-07 13:59:42 UTC
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.

Comment 5 Tomas Hoger 2012-03-15 12:28:18 UTC
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 ) )
 612       string_size--;

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 )
 615     {
 616       FT_ERROR(( "t42_parse_sfnts: invalid string\n" ));
 617       error = T42_Err_Invalid_File_Format;
 618       goto Fail;
 619     }

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