-
Notifications
You must be signed in to change notification settings - Fork 424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read out-of-bounds in TextEndsWithNewline #379
Comments
@gaa-cifasis thank you for your usual detailed report... you certainly come across some weird documents... what characer encoding was the doument supposed to be? It is certainly not utf-8! But as discussed before, tidy should have no problem with any byte sequence... Not in a position to push this to the repo today, but would be much appreciated if you could apply the follow patch, and try again -
The first is because your document contains some high bit characters, and without the The second is in the service Obviously And note here we do add Anyway, will push this fix soonest but would be much appreciated if you could test the patch... This is against the latest |
How this lasted so long in the code is a mystery! But of course it will only be a read out-of-bounds if testing the first character in the lexer, and it is a spacey char. A big thanks to @gaa-cifasis for running ASAN tests on Tidy.
@gaa-cifasis because I am currently doing extensive testing on #380 I have also pushed the above patch to the It would be great if you could checkout In fact every ones help in testing this branch would be most appreciated... it now has two important fixes... thanks... After sufficient testing of this issue and #380 in this branch will be merged to |
@gaa-cifasis this is now in Feel free to re-open, a file a new issue... thanks... |
Hello,
We found a read out-of-bounds in tidy-html5 (git revision 03a643f). A test case to reproduce it is available here. You can see the ASAN report:
==29141== ERROR: AddressSanitizer: heap-buffer-overflow on address 0xb4b000ff at pc 0x81942b8 bp 0xbfffee48 sp 0xbfffee3c
READ of size 1 at 0xb4b000ff thread T0
#0 0x81942b7 (/home/vagrant/afl-tests/progs/tidy-html5/build/cmake/tidy+0x81942b7)
#1 0x81b4233 (/home/vagrant/afl-tests/progs/tidy-html5/build/cmake/tidy+0x81b4233)
#2 0x81b4233 (/home/vagrant/afl-tests/progs/tidy-html5/build/cmake/tidy+0x81b4233)
#3 0x81b74e3 (/home/vagrant/afl-tests/progs/tidy-html5/build/cmake/tidy+0x81b74e3)
#4 0x81b54a3 (/home/vagrant/afl-tests/progs/tidy-html5/build/cmake/tidy+0x81b54a3)
#5 0x81b54a3 (/home/vagrant/afl-tests/progs/tidy-html5/build/cmake/tidy+0x81b54a3)
#6 0x81b54a3 (/home/vagrant/afl-tests/progs/tidy-html5/build/cmake/tidy+0x81b54a3)
#7 0x81b4aeb (/home/vagrant/afl-tests/progs/tidy-html5/build/cmake/tidy+0x81b4aeb)
#8 0x80aaeb7 (/home/vagrant/afl-tests/progs/tidy-html5/build/cmake/tidy+0x80aaeb7)
#9 0x80541af (/home/vagrant/afl-tests/progs/tidy-html5/build/cmake/tidy+0x80541af)
#10 0xb6851a82 (/lib/i386-linux-gnu/libc-2.19.so+0x19a82)
#11 0x8058825 (/home/vagrant/afl-tests/progs/tidy-html5/build/cmake/tidy+0x8058825)
0xb4b000ff is located 1 bytes to the left of 8192-byte region [0xb4b00100,0xb4b02100)
allocated by thread T0 here:
#0 0xb69fc854 (/usr/lib/i386-linux-gnu/libasan.so.0.0.0+0x16854)
#1 0x82040c4 (/home/vagrant/afl-tests/progs/tidy-html5/build/cmake/tidy+0x82040c4)
Shadow bytes around the buggy address:
0x3695ffc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x3695ffd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x3695ffe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x3695fff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x36960000: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x36960010: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa[fa]
0x36960020:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x36960030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x36960040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x36960050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x36960060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
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
Heap righ redzone: fb
Freed Heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
ASan internal: fe
==29141== ABORTING
and the gdb backtrace is here:
(gdb) bt
#0 0xb7fdd428 in __kernel_vsyscall ()
#1 0xb6866607 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#2 0xb6869a33 in __GI_abort () at abort.c:89
#3 0xb6a042e4 in ?? () from /usr/lib/i386-linux-gnu/libasan.so.0
#4 0xb69f858a in ?? () from /usr/lib/i386-linux-gnu/libasan.so.0
#5 0xb6a00f4b in ?? () from /usr/lib/i386-linux-gnu/libasan.so.0
#6 0xb69ffd3a in __asan_report_error () from /usr/lib/i386-linux-gnu/libasan.so.0
#7 0xb69f88ff in __asan_report_load1 () from /usr/lib/i386-linux-gnu/libasan.so.0
#8 0x081942b8 in TextEndsWithNewline (lexer=, mode=25, node=0xb49017c0)
#9 PPrintText (doc=0xb6601d00, mode=25, indent=0, node=0xb49017c0)
#10 0x081b4234 in PPrintScriptStyle (node=0xb4901830, indent=0, mode=25, doc=0xb6601d00)
#11 prvTidyPPrintTree (doc=0xb6601d00, mode=25, indent=0, node=0xb4901830)
#12 0x081b4234 in PPrintScriptStyle (node=0xb4901910, indent=0, mode=25, doc=0xb6601d00)
#13 prvTidyPPrintTree (doc=0xb6601d00, mode=0, indent=0, node=0xb4901910)
#14 0x081b74e4 in prvTidyPPrintTree (doc=0xb6601d00, mode=0, indent=0, node=0xb49019f0)
#15 0x081b54a4 in prvTidyPPrintTree (doc=0xb6601d00, mode=0, indent=0, node=0xb4901bb0)
#16 0x081b54a4 in prvTidyPPrintTree (doc=0xb6601d00, mode=0, indent=0, node=0xb4901a60)
#17 0x081b54a4 in prvTidyPPrintTree (doc=0xb6601d00, mode=0, indent=0, node=0xb4901b40)
---Type to continue, or q to quit---
#18 0x081b4aec in prvTidyPPrintTree (doc=0xb6601d00, mode=0, indent=0, node=0xb6601d00)
#19 0x080aaeb8 in tidyDocSaveStream (out=0xb6400640, doc=0xb6601d00)
#20 tidyDocSaveStdout (doc=0xb6601d00) at /home/vagrant/afl-tests/progs/tidy-html5/src/tidylib.c:1096
#21 tidySaveStdout (tdoc=tdoc@entry=0xb6601d00) at /home/vagrant/afl-tests/progs/tidy-html5/src/tidylib.c:997
#22 0x080541b0 in main (argc=2, argv=) at /home/vagrant/afl-tests/progs/tidy-html5/console/tidy.c:1943
Regards,
Gus.
The text was updated successfully, but these errors were encountered: