FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Sanitizer fixes by QuLogic · Pull Request #9239 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cpp  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 4 additions & 1 deletion extern/ttconv/pprdrv_tt.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ BYTE *GetTable(struct TTFONT *font, const char *name)

offset = getULONG( ptr + 8 );
length = getULONG( ptr + 12 );
table = (BYTE*)calloc( sizeof(BYTE), length );
table = (BYTE*)calloc( sizeof(BYTE), length + 2 );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This looks a bit tricky to review, can you provide a pointer (hehe) to where you expect table to be null-terminated?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Well, there's only one more diff chunk in this file. ;)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I know, but what I mean is that it's not clear from the codeflow how the return value of GetTable is later used with the expectation that it is null-terminated. (I am not asking you to unwrap the whole codeflow, just some hint that this is correct...)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ah, you mean where the code expects NUL-termination? See the backtrace in the commit:

ERROR: AddressSanitizer: heap-buffer-overflow on address 0x617000235709 at pc 0x7f95efd3c48a bp 0x7ffe41b6ecc0 sp 0x7ffe41b6ecb0
READ of size 1 at 0x617000235709 thread T0
    #0 0x7f95efd3c489 in utf16be_to_ascii extern/ttconv/pprdrv_tt.cpp:178
    #1 0x7f95efd3c489 in Read_name(TTFONT*) extern/ttconv/pprdrv_tt.cpp:339
    #2 0x7f95efd499ef in read_font(...) extern/ttconv/pprdrv_tt.cpp:1325
    #3 0x7f95efd4c602 in get_pdf_charprocs(...) extern/ttconv/pprdrv_tt.cpp:1420
    #4 0x7f95efd35c22 in py_get_pdf_charprocs src/_ttconv.cpp:217

0x617000235709 is located 1 bytes to the right of 648-byte region [0x617000235480,0x617000235708)
allocated by thread T0 here:
    #0 0x7f9612262a38 in __interceptor_calloc (/usr/lib64/libasan.so.4+0xdea38)
    #1 0x7f95efd3b261 in GetTable(TTFONT*, char const*) extern/ttconv/pprdrv_tt.cpp:140

Read_name calls utf16be_to_ascii with some pointer in the middle of the table + a length, but it also checks for NUL-termination to ensure no overflows.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ah, I see, should have read the commit message :-) Thanks!


try
{
Expand All @@ -160,6 +160,9 @@ BYTE *GetTable(struct TTFONT *font, const char *name)
free(table);
throw;
}
/* Always NUL-terminate; add two in case of UTF16 strings. */
table[length] = '\0';
table[length + 1] = '\0';
return table;
}

Expand Down
4 changes: 1 addition & 3 deletions src/ft2font.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,7 @@ void FT2Font::set_text(
FT_Bool use_kerning = FT_HAS_KERNING(face);
FT_UInt previous = 0;

glyphs.resize(0);
pen.x = 0;
pen.y = 0;
clear();

anntzer Sep 27, 2017 •
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Note for the future reviewer: this additionally calls FT_Done_Glyph on each element of glyph.
This parts looks good to me.


bbox.xMin = bbox.yMin = 32000;
bbox.xMax = bbox.yMax = -32000;
Expand Down

Back | FazBrowse Home | New Git URL