Repository navigation
🐛 fix(parse): stop the SSE2 text scan at NUL - #2467
Conversation
The one-byte data scan on SSE2 tested each 32-byte block for '&' and '<' only, so a NUL inside such a block was stepped over. The data state never saw it, and parse() dropped its unexpected-null-character error. The 16-byte loops and the NEON scan already stop at a zero byte, and a streamed parse reported the error because a small chunk never reaches the 32-byte loop. The smallest input that shows it is 48 bytes: 16 ordinary characters, a NUL, then 31 more. html5lib-tests (tokenizer/test2.test, "Null Byte Replacement") expects the error for a NUL in the data state, so the streamed side was right. Tests cover the NUL in each scan block, the string from the differential run, and a seeded sample of 300 Latin-1 and mixed-width strings, streamed at chunk sizes 1, 2, 3, 7 and 4096.
Merging this PR will degrade performance by 2.83%2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
parse('a' * 16 + '\x00' + 'b' * 31).errorsis empty on x86-64, while streaming the same string reports('unexpected-null-character', 1, 16). The one-byte data scan's 32-byte SSE2 loop tested each block for&and<only, so a NUL inside a block was stepped over and the data state never reported it. The 16-byte loops and the NEON scan already stop at a zero byte, and a streamed parse reports the error because small chunks never reach the 32-byte loop.html5lib-tests (
tokenizer/test2.test, "Null Byte Replacement") expects the error for a NUL in the data state, so the one-shot side was wrong. The 32-byte loop now stops at a NUL as it does at&and<.Tests cover a NUL in each scan block, the string a differential run found, and a seeded sample of 300 Latin-1 and mixed-width strings streamed at chunk sizes 1, 2, 3, 7 and 4096, asserting the stream reports exactly what
parse()does. Eleven of them fail without the fix.