https://bugs.winehq.org/show_bug.cgi?id=45422
Bug ID: 45422 Summary: ./tools/sfnt2fon/sfnt2fon.c shows a heap buffer overflow fill_fontinfo() Product: Wine Version: 3.11 Hardware: x86 URL: https://bugs.winehq.org/show_bug.cgi?id=40330 OS: Linux Status: NEW Keywords: download, source, valgrind Severity: normal Priority: P2 Component: tools Assignee: wine-bugs@winehq.org Reporter: austinenglish@gmail.com Distribution: Gentoo
First noticed in #40330, with ASAN: ../tools/sfnt2fon/sfnt2fon -o sserifee.fon ms_sans_serif.ttf -d 129 13,1250,5 16,1250,7 ================================================================= ==18356==ERROR: AddressSanitizer: heap-buffer-overflow on address 0xf5a06ab3 at pc 0x5658546e bp 0xffd67ec8 sp 0xffd67eb8 READ of size 1 at 0xf5a06ab3 thread T0 #0 0x5658546d in fill_fontinfo (/var/lib/jenkins/home/workspace/wine-gcc-asan/tools/sfnt2fon/sfnt2fon+0x946d) #1 0x56585da8 in main (/var/lib/jenkins/home/workspace/wine-gcc-asan/tools/sfnt2fon/sfnt2fon+0x9da8) #2 0xf7680302 in __libc_start_main (/lib32/libc.so.6+0x18302) #3 0x56582070 (/var/lib/jenkins/home/workspace/wine-gcc-asan/tools/sfnt2fon/sfnt2fon+0x6070)
0xf5a06ab3 is located 1 bytes to the right of 2-byte region [0xf5a06ab0,0xf5a06ab2) allocated by thread T0 here: #0 0xf7a42ed4 in malloc (/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/32/libasan.so.4+0xe5ed4) #1 0xf785e437 (/usr/lib32/libfreetype.so.6+0x9437)
SUMMARY: AddressSanitizer: heap-buffer-overflow (/var/lib/jenkins/home/workspace/wine-gcc-asan/tools/sfnt2fon/sfnt2fon+0x946d) in fill_fontinfo Shadow bytes around the buggy address: 0x3eb40d00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x3eb40d10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x3eb40d20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x3eb40d30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x3eb40d40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa =>0x3eb40d50: fa fa fa fa fa fa[02]fa fa fa fd fa fa fa fd fa 0x3eb40d60: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd 0x3eb40d70: fa fa fd fa fa fa fd fd fa fa fd fa fa fa fd fd 0x3eb40d80: fa fa fd fa fa fa fd fa fa fa fd fa fa fa fd fa 0x3eb40d90: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x3eb40da0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb ==18356==ABORTING
Using Valgrind gets better line numbers: austin@valgrindbox ~/wine-valgrind/fonts $ . ~/src/wine-valgrind/scripts/vg-wrapper.sh
austin@valgrindbox ~/wine-valgrind/fonts $ valgrind make sserifee.fon ../tools/sfnt2fon/sfnt2fon -o sserifee.fon ms_sans_serif.ttf -d 129 13,1250,5 16,1250,7 ==20606== Invalid read of size 1 ==20606== at 0x10A91E: fill_fontinfo (sfnt2fon.c:577) ==20606== by 0x10AD1F: main (sfnt2fon.c:729) ==20606== Address 0x4be6f03 is 1 bytes after a block of size 2 alloc'd ==20606== at 0x482D58B: malloc (vg_replace_malloc.c:299) ==20606== by 0x487DD87: ft_alloc (ftsystem.c:102) ==20606== by 0x488592E: ft_mem_qalloc (ftutil.c:76) ==20606== by 0x488592E: ft_mem_alloc (ftutil.c:55) ==20606== by 0x488632E: ft_glyphslot_alloc_bitmap (ftobjs.c:490) ==20606== by 0x48C2D62: tt_sbit_decoder_alloc_bitmap (ttsbit.c:628) ==20606== by 0x48C2D62: tt_sbit_decoder_load_bitmap (ttsbit.c:1234) ==20606== by 0x48C2D62: tt_sbit_decoder_load_image (ttsbit.c:1439) ==20606== by 0x48C8265: tt_face_load_sbit_image (ttsbit.c:1616) ==20606== by 0x489F269: load_sbit_image (ttgload.c:2308) ==20606== by 0x489F269: TT_Load_Glyph (ttgload.c:2716) ==20606== by 0x489F269: tt_glyph_load (ttdriver.c:468) ==20606== by 0x4882E0F: FT_Load_Glyph (ftobjs.c:913) ==20606== by 0x488371D: FT_Load_Char (ftobjs.c:1051) ==20606== by 0x10A9F7: fill_fontinfo (sfnt2fon.c:550) ==20606== by 0x10AD1F: main (sfnt2fon.c:729) ==20606==
https://bugs.winehq.org/show_bug.cgi?id=45422
Austin English austinenglish@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Summary|./tools/sfnt2fon/sfnt2fon.c |./tools/sfnt2fon/sfnt2fon.c |shows a heap buffer |shows a heap buffer |overflow fill_fontinfo() |overflow in fill_fontinfo()
https://bugs.winehq.org/show_bug.cgi?id=45422
--- Comment #1 from Austin English austinenglish@gmail.com --- Also occurs on line 550 according to valgrind:
17:34:39 ==19701== Invalid read of size 1 17:34:39 ==19701== at 0x10A6CF: main (sfnt2fon.c:577) 17:34:39 ==19701== Address 0x4bd758b is 1 bytes after a block of size 2 alloc'd 17:34:39 ==19701== at 0x482D58B: malloc (vg_replace_malloc.c:299) 17:34:39 ==19701== by 0x487DB27: ft_alloc (ftsystem.c:102) 17:34:39 ==19701== by 0x48831E3: ft_mem_qalloc (ftutil.c:76) 17:34:39 ==19701== by 0x4883244: ft_mem_alloc (ftutil.c:55) 17:34:39 ==19701== by 0x488464B: ft_glyphslot_alloc_bitmap (ftobjs.c:355) 17:34:39 ==19701== by 0x48C62CB: tt_sbit_decoder_alloc_bitmap (ttsbit.c:619) 17:34:39 ==19701== by 0x48C62CB: tt_sbit_decoder_load_bitmap (ttsbit.c:1224) 17:34:39 ==19701== by 0x48C62CB: tt_sbit_decoder_load_image (ttsbit.c:1429) 17:34:39 ==19701== by 0x48CB4D5: tt_face_load_sbit_image (ttsbit.c:1599) 17:34:39 ==19701== by 0x489D6E1: load_sbit_image (ttgload.c:2226) 17:34:39 ==19701== by 0x489D6E1: TT_Load_Glyph (ttgload.c:2623) 17:34:39 ==19701== by 0x489D6E1: tt_glyph_load (ttdriver.c:468) 17:34:39 ==19701== by 0x4883DC0: FT_Load_Glyph (ftobjs.c:758) 17:34:39 ==19701== by 0x48845DD: FT_Load_Char (ftobjs.c:887) 17:34:39 ==19701== by 0x10A585: main (sfnt2fon.c:550)
https://bugs.winehq.org/show_bug.cgi?id=45422
--- Comment #2 from Austin English austinenglish@gmail.com --- Created attachment 61880 --> https://bugs.winehq.org/attachment.cgi?id=61880 patch from wine-patches
This patch fixes the issue for me. From https://source.winehq.org/patches/data/148941
https://bugs.winehq.org/show_bug.cgi?id=45422
Anton Baskanov baskanov@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |baskanov@gmail.com
--- Comment #3 from Anton Baskanov baskanov@gmail.com --- Fixed by commit 2e2609083851ba2c70aee89bb9e23a2c7d82d867.
https://bugs.winehq.org/show_bug.cgi?id=45422
Austin English austinenglish@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Fixed by SHA1| |2e2609083851ba2c70aee89bb9e | |23a2c7d82d867 Status|NEW |RESOLVED Resolution|--- |FIXED
--- Comment #4 from Austin English austinenglish@gmail.com --- (In reply to Anton Baskanov from comment #3)
Fixed by commit 2e2609083851ba2c70aee89bb9e23a2c7d82d867.
Thanks! I can't reproduce it on my current setup (i.e., even after reverting the fix), so assuming fixed.
https://bugs.winehq.org/show_bug.cgi?id=45422
--- Comment #5 from Anton Baskanov baskanov@gmail.com --- (In reply to Austin English from comment #4)
(In reply to Anton Baskanov from comment #3)
Fixed by commit 2e2609083851ba2c70aee89bb9e23a2c7d82d867.
Thanks! I can't reproduce it on my current setup (i.e., even after reverting the fix), so assuming fixed.
Yeah, I've also fixed the glyphs that were causing the overflow.
https://bugs.winehq.org/show_bug.cgi?id=45422
Alexandre Julliard julliard@winehq.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED
--- Comment #6 from Alexandre Julliard julliard@winehq.org --- Closing bugs fixed in 7.5.