GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Infinite loop with unbounded memory on a 4-byte UTF-16 file that ends in an identifier character · Issue #693 · cppcheck-opensource/simplecpp Open DescriptionSummaryA 4-byte file consisting of a UTF-16 BOM plus one identifier character, with no newline after $ printf '\xFF\xFE\x41\x00' > poc.c # UTF-16 LE BOM + 'A' $ ./simplecpp poc.c (never returns) Measured on the standalone This is adjacent to #637 / #636 but is a different path: #637's exact bytes VersionReproduced on $ g++ -std=c++11 -O2 -o simplecpp main.cpp simplecpp.cppHost: Linux x86-64, GCC. Trigger matrix
So it needs all three of: a UTF-16 BOM, a final character that continues an identifier, and Cause
void unget_internal(int ch) { if (isUtf16) { // TODO: use ungetc() as well // UTF-16 has subsequent unget() calls fseek(file, -1, SEEK_CUR); } else { ungetc(ch, file); } }
int peek() override { // keep lastCh intact const int ch = fgetc(file); unget_internal(ch); return ch; } At end of file that Possible fixSkipping the rewind when nothing was consumed fixes every case in the table above: --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -463,7 +463,8 @@ if (isUtf16) { // TODO: use ungetc() as well // UTF-16 has subsequent unget() calls - fseek(file, -1, SEEK_CUR); + if (ch != EOF) + fseek(file, -1, SEEK_CUR); } else { ungetc(ch, file); } With that applied, I have not checked whether this is the fix you would prefer — you may want to handle it at the if (isUtf16) { (void)get(); const auto ch2 = static_cast<unsigned char>(peek()); // EOF (-1) becomes 0xFF here unget(); the second Also affects cppcheckcppcheck vendors this file in How it was foundAutomated fuzzing of cppcheck; the input was then minimised by hand to the 4 bytes above and ActivityMetadataMetadataAssigneesLabelsNo labels TypeProjectsMilestoneRelationshipsDevelopmentIssue actions | ||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |