René's URL Explorer Experiment


Title: Infinite loop with unbounded memory on a 4-byte UTF-16 file that ends in an identifier character · Issue #693 · cppcheck-opensource/simplecpp · GitHub

Open Graph Title: Infinite loop with unbounded memory on a 4-byte UTF-16 file that ends in an identifier character · Issue #693 · cppcheck-opensource/simplecpp

X Title: Infinite loop with unbounded memory on a 4-byte UTF-16 file that ends in an identifier character · Issue #693 · cppcheck-opensource/simplecpp

Description: Summary A 4-byte file consisting of a UTF-16 BOM plus one identifier character, with no newline after it, makes simplecpp loop forever at ~100 % CPU while allocating without bound. $ printf '\xFF\xFE\x41\x00' > poc.c # UTF-16 LE BOM + 'A...

Open Graph Description: Summary A 4-byte file consisting of a UTF-16 BOM plus one identifier character, with no newline after it, makes simplecpp loop forever at ~100 % CPU while allocating without bound. $ printf '\xFF\x...

X Description: Summary A 4-byte file consisting of a UTF-16 BOM plus one identifier character, with no newline after it, makes simplecpp loop forever at ~100 % CPU while allocating without bound. $ printf '\x...

Opengraph URL: https://github.com/cppcheck-opensource/simplecpp/issues/693

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Infinite loop with unbounded memory on a 4-byte UTF-16 file that ends in an identifier character","articleBody":"\n\n## Summary\n\nA 4-byte file consisting of a UTF-16 BOM plus one identifier character, with no newline after\nit, makes `simplecpp` loop forever at ~100 % CPU while allocating without bound.\n\n```console\n$ printf '\\xFF\\xFE\\x41\\x00' > poc.c    # UTF-16 LE BOM + 'A'\n$ ./simplecpp poc.c\n  (never returns)\n```\n\nMeasured on the standalone `simplecpp` binary, sampling `/proc/\u003cpid>/status`:\n\n```\nt= 20s  rss=0.31 GB  cpu=100%\nt= 60s  rss=0.78 GB  cpu= 95%\nt=120s  rss=1.63 GB  cpu= 97%\nt=180s  rss=2.39 GB  cpu= 98%     (still climbing linearly, ~13 MB/s)\n```\n\nThis is adjacent to #637 / #636 but is a different path: #637's exact bytes\n(`\\xFF\\xFE\\x00\\x3B`) are fixed and complete instantly on current master; the case above does not.\n\n## Version\n\nReproduced on `master` at `f420e61` (\"Fix #688: Support `#elifdef` and `#elifndef` (#691)\",\n2026-08-03), built exactly as the README describes, with no sanitizers and no fuzzing engine:\n\n```console\n$ g++ -std=c++11 -O2 -o simplecpp main.cpp simplecpp.cpp\n```\n\nHost: Linux x86-64, GCC.\n\n## Trigger matrix\n\n| bytes | meaning | result |\n| --- | --- | --- |\n| `FF FE 41 00` | UTF-16 LE BOM + `A` | **hang** |\n| `FE FF 00 41` | UTF-16 BE BOM + `A` | **hang** |\n| `FF FE 24 00` | UTF-16 LE BOM + `$` | **hang** |\n| `FE FF 00 3B` | UTF-16 BE BOM + `;` | ok |\n| `FF FE 41 00 00 00` | LE BOM + `A` + NUL | ok |\n| `FF FE 41 00 0A 00` | LE BOM + `A` + newline | ok |\n| `41` | plain UTF-8 `A`, no BOM | ok |\n| `FF FE 00 3B` | the bytes from #637 | ok (fixed) |\n| `FF FE` | BOM only | ok |\n\nSo it needs all three of: a UTF-16 BOM, a final character that continues an identifier, and\nnothing after it. A trailing newline avoids it, which is presumably why ordinary files do not\nhit this.\n\n## Cause\n\n`FileStream::unget_internal()` rewinds unconditionally in the UTF-16 branch:\n\n```cpp\nvoid unget_internal(int ch) {\n    if (isUtf16) {\n        // TODO: use ungetc() as well\n        // UTF-16 has subsequent unget() calls\n        fseek(file, -1, SEEK_CUR);\n    } else {\n        ungetc(ch, file);\n    }\n}\n```\n\n`FileStream::peek()` calls `fgetc()` and then hands the result straight to `unget_internal()`:\n\n```cpp\nint peek() override {\n    // keep lastCh intact\n    const int ch = fgetc(file);\n    unget_internal(ch);\n    return ch;\n}\n```\n\nAt end of file that `fgetc()` consumes nothing and returns `EOF`, but the `fseek(-1)` still runs,\nso every `peek()` past the end moves the read position one byte *backwards*. The reader can then\nnever reach the end, and `readfile()` keeps appending tokens — hence both the spin and the memory\ngrowth. The `ungetc()` branch does not have the problem because `ungetc(EOF, …)` is a no-op.\n\n## Possible fix\n\nSkipping the rewind when nothing was consumed fixes every case in the table above:\n\n```diff\n--- a/simplecpp.cpp\n+++ b/simplecpp.cpp\n@@ -463,7 +463,8 @@\n             if (isUtf16) {\n                 // TODO: use ungetc() as well\n                 // UTF-16 has subsequent unget() calls\n-                fseek(file, -1, SEEK_CUR);\n+                if (ch != EOF)\n+                    fseek(file, -1, SEEK_CUR);\n             } else {\n                 ungetc(ch, file);\n             }\n```\n\nWith that applied, `make testrunner && ./testrunner` still exits 0, and all nine inputs in the\ntable behave as \"ok\".\n\nI have not checked whether this is the fix you would prefer — you may want to handle it at the\ncall site instead. While reading that code I noticed something adjacent that looks unintended,\nin `Stream::peekChar()`:\n\n```cpp\nif (isUtf16) {\n    (void)get();\n    const auto ch2 = static_cast\u003cunsigned char>(peek());   // EOF (-1) becomes 0xFF here\n    unget();\n```\n\nthe second `peek()` is cast to `unsigned char` without an `EOF` check, so a truncated final\nUTF-16 unit is silently read as `0xFF`. That is not what makes the loop above spin — the\n`unget_internal` change alone is enough — but it may be worth a look.\n\n## Also affects cppcheck\n\ncppcheck vendors this file in `externals/simplecpp`, and the same input reaches it through\n`CppCheck::check(FileWithDetails)` → `simplecpp::TokenList::TokenList(filename, …)`, which is the\npath `cppcheck \u003cfile>` uses. I observed the identical hang there (via the OSS-Fuzz `cppcheck`\ntarget, ASan build): 100 % CPU with RSS at 4.9 GB after 288 s on a 68-byte UTF-16 file that ends\nin `M`. The standalone reproducer above is self-contained, so nothing in this report depends on\nthat build.\n\n## How it was found\n\nAutomated fuzzing of cppcheck; the input was then minimised by hand to the 4 bytes above and\nre-verified against upstream `simplecpp` master, so the reproducer involves no fuzzing harness.\n","author":{"url":"https://github.com/CrJyyy","@type":"Person","name":"CrJyyy"},"datePublished":"2026-08-04T06:23:36Z","url":"https://github.com/cppcheck-opensource/simplecpp/issues/693"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:00e6c6d7-6daa-dad7-cb35-cc0f8104f2be
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC38E:2DF45D:205AC1:2CC0BF:6AFC4ABA
html-safe-nonce373db572bc4da8970aa4fa0765d7675b47ab3401abebef4ac4196635fb426bab
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzhFOjJERjQ1RDoyMDVBQzE6MkNDMEJGOjZBRkM0QUJBIiwidmlzaXRvcl9pZCI6IjgyMzEwMjcxNzIxMjMxMDE4ODIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmace41afc3eafd52b6822def201a920c30f00bbb179b1392d3e50438d291fb62029
hovercard-subject-tagissue:5057409772
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/cppcheck-opensource/simplecpp/693/issue_layout
twitter:imagehttps://opengraph.githubassets.com/6a0464acbda4de62ed5a59ce5ec51b1ca17f03bde2b8af9c4a0cca67a117f64e/cppcheck-opensource/simplecpp/issues/693
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/6a0464acbda4de62ed5a59ce5ec51b1ca17f03bde2b8af9c4a0cca67a117f64e/cppcheck-opensource/simplecpp/issues/693
og:image:altSummary A 4-byte file consisting of a UTF-16 BOM plus one identifier character, with no newline after it, makes simplecpp loop forever at ~100 % CPU while allocating without bound. $ printf '\xFF\x...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameCrJyyy
hostnamegithub.com
expected-hostnamegithub.com
None20dfdada12bc00bbf8065dc10dfe3ff3711b85db5cc117f83296f8074e861960
turbo-cache-controlno-preview
go-importgithub.com/cppcheck-opensource/simplecpp git https://github.com/cppcheck-opensource/simplecpp.git
octolytics-dimension-user_id278097703
octolytics-dimension-user_logincppcheck-opensource
octolytics-dimension-repository_id33434464
octolytics-dimension-repository_nwocppcheck-opensource/simplecpp
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id33434464
octolytics-dimension-repository_network_root_nwocppcheck-opensource/simplecpp
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release041909865f220ab51714e7efdc276dd349a99ade
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/cppcheck-opensource/simplecpp/issues/693#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcppcheck-opensource%2Fsimplecpp%2Fissues%2F693
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcppcheck-opensource%2Fsimplecpp%2Fissues%2F693
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=cppcheck-opensource%2Fsimplecpp
Reloadhttps://github.com/cppcheck-opensource/simplecpp/issues/693
Reloadhttps://github.com/cppcheck-opensource/simplecpp/issues/693
Reloadhttps://github.com/cppcheck-opensource/simplecpp/issues/693
cppcheck-opensourcehttps://github.com/cppcheck-opensource
simplecpphttps://github.com/cppcheck-opensource/simplecpp
Codehttps://github.com/cppcheck-opensource/simplecpp
Issues86 (86)https://github.com/cppcheck-opensource/simplecpp/issues
Pull requests36 (36)https://github.com/cppcheck-opensource/simplecpp/pulls
Actionshttps://github.com/cppcheck-opensource/simplecpp/actions
Wikihttps://github.com/cppcheck-opensource/simplecpp/wiki
Security and qualityhttps://github.com/cppcheck-opensource/simplecpp/security
Insightshttps://github.com/cppcheck-opensource/simplecpp/pulse
https://github.com/cppcheck-opensource/simplecpp
New issuehttps://github.com/login?return_to=https://github.com/cppcheck-opensource/simplecpp/issues/693
New issuehttps://github.com/login?return_to=https://github.com/cppcheck-opensource/simplecpp/issues/693
Infinite loop with unbounded memory on a 4-byte UTF-16 file that ends in an identifier characterhttps://github.com/cppcheck-opensource/simplecpp/issues/693#top
https://github.com/CrJyyy
CrJyyyhttps://github.com/CrJyyy
on Aug 4, 2026https://github.com/cppcheck-opensource/simplecpp/issues/693#issue-5057409772
#637https://github.com/cppcheck-opensource/simplecpp/issues/637
#636https://github.com/cppcheck-opensource/simplecpp/pull/636
#637https://github.com/cppcheck-opensource/simplecpp/issues/637
#688https://github.com/cppcheck-opensource/simplecpp/issues/688
#691https://github.com/cppcheck-opensource/simplecpp/pull/691
#637https://github.com/cppcheck-opensource/simplecpp/issues/637
Sign up for freehttps://github.com/signup?return_to=https://github.com/cppcheck-opensource/simplecpp/issues/693
Sign in to commenthttps://github.com/login?return_to=https://github.com/cppcheck-opensource/simplecpp/issues/693
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.