schnaader / fairytale

encode.ru community archiver
GNU Lesser General Public License v3.0
31 stars 13 forks source link

JSON parser causes program to enter infinite loop #26

Closed andrew-epstein closed 6 years ago

andrew-epstein commented 6 years ago

@M-Gonzalo found an issue with a PDF file that causes the new JSON parser to continually output 1 byte detections at position 18446744073709551615, which is probably the result of a -1 getting cast to a uint64_t.

I was able to reproduce this issue on OSX yesterday. However, when I try the same thing again, I get numerous 1 byte JSON detections, followed by an infinite repeating cycle as follows:

Possible text detection at 0, 1935 bytes
Possible text detection at 3907, 1119 bytes
Possible text detection at 37668, 22694 bytes
Possible text detection at 72364, 19153 bytes
Possible text detection at 103772, 23085 bytes
Possible text detection at 137207, 11849 bytes
Possible text detection at 751182, 1741 bytes
andrew-epstein commented 6 years ago

Edit: Turns out this is unrelated.

Compiling with clang's -fsanitize=undefined reveals the following, but I don't know if it's related, as it happens a while before the bad detections crop up:

zLib stream found at 371942, length 10967 bytes, decompresses to 46023 bytes, 0 penalty bytes
zLib stream found at 382986, length 9374 bytes, decompresses to 39958 bytes, 0 penalty bytes
/Users/epsteina/code/personal/fairytale/transforms/zlibtransform.cpp:168:32: runtime error: load of misaligned address 0x0001052be01a for type 'uint64_t' (aka 'unsigned long long'), which requires 8 byte alignment
0x0001052be01a: note: pointer points here
 00 00  78 9c ec dd 21 72 f2 5a  18 06 60 53 59 5d 85 aa  8b 46 c5 c6 47 a2 71 6c  a1 16 d5 25 74 26
              ^
/Users/epsteina/code/personal/fairytale/transforms/zlibtransform.cpp:168:43: runtime error: load of misaligned address 0x00010528e01a for type 'uint64_t' (aka 'unsigned long long'), which requires 8 byte alignment
0x00010528e01a: note: pointer points here
 00 00  78 9c ec 9d ad 72 1b cd  d3 c5 89 61 b0 51 90 99  b1 91 a9 b9 a1 b0 99 6e  c1 34 28 97 f0 54
              ^
zLib stream found at 392544, length 34793 bytes, decompresses to 815796 bytes, 0 penalty bytes
zLib stream found at 427414, length 9660 bytes, decompresses to 40836 bytes, 0 penalty bytes
zLib stream found at 437151, length 9087 bytes, decompresses to 39209 bytes, 0 penalty bytes