bugThe FreeType Project - Bugs: bug #46255, Malformed Type42 font takes a long...


You are not allowed to post comments on this tracker with your current authentication level.

bug #46255: Malformed Type42 font takes a long time to parse.

Submitter:  bungeman <bungeman>
Submitted:  Mon 19 Oct 2015 10:26:04 PM UTC
Severity:  3 - Normal Item Group:  Incorrect behaviour
Status:  Fixed Privacy:  Public
Assigned to:  wl Open/Closed:  Closed
Planned Release:  2.6.2

Wed 21 Oct 2015 05:03:29 AM UTC, comment #4: 

Thanks for the report and patch; I've fixed it slightly differently in the git.

Werner LEMBERG <wl>
Group administrator
Tue 20 Oct 2015 07:56:30 PM UTC, comment #3: 

I've locally applied the attached 'type42.diff' to my source to work around this. This applies the same "(FT_Long)( limit - parser->root.cursor ) < face->ttf_size" check done in the BEFORE_START case to the BEFORE_TABLE_DIR case.

(file #35245)

bungeman <bungeman>
Tue 20 Oct 2015 05:59:47 PM UTC, comment #2: 

In this case there is one single huge allocation which happens in t42_parse_sfnts on the lines like

if ( FT_REALLOC( face->ttf_data, 12 + 16 * num_tables,
face->ttf_size + 1 ) )

because 'face->ttf_size' is 1913035808. A few lines up is the cause

len = FT_PEEK_ULONG( p );

this len and the resulting face->ttf_size should be checked for sanity.

bungeman <bungeman>
Tue 20 Oct 2015 03:14:10 PM UTC, comment #1: 

I ran this with an un-instrumented build of FreeType/runonce doing something like

freetype2$ ./configure
freetype2$ make -j32
freetype2$ g++ -std=c++11 src/tools/ftfuzzer/ftfuzzer.cc src/tools/ftfuzzer/runinput.cc -I include objs/.libs/libfreetype.a -lbz2 -lz -lpng -lharfbuzz -larchive -o objs/runinput
freetype2$ /usr/bin/time objs/runinput 6efffbcd9e11318b86881506a4b0d2c7b0f489a9

which produces

36.94user 0.31system 0:37.33elapsed 99%CPU (0avgtext+0avgdata 1870424maxresident)k
512inputs+0outputs (2major+2713minor)pagefaults 0swaps

So it looks like this is taking over half a minute and allocates ~1.8GB without the overhead of sanitizers (which approximately doubles time and memory). The perf results look the same as previous.

bungeman <bungeman>
Mon 19 Oct 2015 10:26:04 PM UTC, original submission:  

Found with libFuzzer with FreeType 5179c89f61aa6b, reproduction attached.

When running through ftfuzzer/runinput.cc this malformed Type42 font takes a very long time to parse (at least a full minute on my local machine) which seems like quite a bit for a 6K input. Perf says that all of the time is in t42_parse_sfnts (18%) and two functions it calls, ps_parser_skip_PS_token (45%) and ps_parser_to_bytes (32%).

bungeman <bungeman>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #35245:  type42.diff added by bungeman (633B - text/x-patch)
file #35234:  6efffbcd9e11318b86881506a4b0d2c7b0f489a9 added by bungeman (6KiB - application/octet-stream)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by wl (Posted a comment)
  • -email is unavailable- added by bungeman (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.


    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-10-21 wl Item GroupWishlist Incorrect behaviour
        StatusNone Fixed
        Assigned toNone wl
        Open/ClosedOpen Closed
        Planned ReleaseNone 2.6.2
    2015-10-20 bungeman Attached File- Added type42.diff, #35245
    2015-10-19 bungeman Attached File- Added 6efffbcd9e11318b86881506a4b0d2c7b0f489a9, #35234

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code