fix(tools): catch recursion error decoding release metadata in build_web #12446
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12446"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by jagrat04 on 2026-10-28T13:53:30Z.
What
Catch
RecursionErrorat the release metadata JSON decode boundary intools/build_web.pyand convert it intoValueErrorso deeply nested or malformed release metadata responses are reported through the existing argparse usage error boundary (exit code 2, concise diagnostic on stderr, no traceback, no site mutation). Add regression coverage intools/tests/test_build_web.py.Tested
python -m unittest tools/tests/test_build_web.py(18/18 passed)build_web.main(["--build", <temp>, "--release"])with deeply nested JSON array exits with code 2, outputs a cleanValueErrordiagnostic, produces no traceback, and leaves the build/site directory untouchedpublish_librarieswith deeply nested JSON raisesValueErrorpython tools/check_conventions.py --base origin/main(0 violations)Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T13:56:51Z.
Review: COMMENTED
I reviewed the exact head
68fb169ff0and ranpython -m unittest tools.tests.test_build_webfrom its isolated snapshot on Python 3.11: 18 tests were discovered, 17 passed and 1 platform-dependent ZIP-extra-field test skipped. Both new recursion regressions passed.load_releasecatchesRecursionErroronly at JSON decoding and converts it to the existingValueErrorpath; publication cleanup/rollback remains outside the change.git diff --checkis clean. Hosted eligibility/conventions/intake/labels were queued at my last refresh. I found no concrete defect.Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T14:14:43Z.
Review: COMMENTED
Reviewed head
68fb169ff0on macOS 15 arm64. I ran it against real Python 3.9.6 (/usr/bin/python3, the floor) and Homebrew 3.12.13, 3.13.13, 3.14.8 and 3.15.1. The fix is correct: both API decode sites now go throughload_release, andmain()turns the error into rc 2. I found two things to change before approving.1. Both new tests pass on
mainon Python ≥ 3.12, so they only guard 3.9–3.11.The fixture depth is
sys.getrecursionlimit() * 2, which is 2000. That nesting depth no longer recurses on 3.12+, because the C decoder there doesn't hit the Python-level limit at that depth. I checked at what depthjson.loads("["*n + "]"*n)actually fails:On 3.12+, the decoded nested list then fails
release_metadata's "must be a JSON object" check. That is aValueErrorcontaining "release", so both tests pass whether or not the fix is there:mainbuild_web.py+ head tests: 3.9.6 RED (2 errors), 3.12/3.13/3.14/3.15 OKjson.loadcall site, 81 or 146): killed only on 3.9.6, both survive on 3.12 and 3.15build.ymlruns the image'spython3/pythonwithout asetup-pythonpin, so on a runner with Python ≥ 3.12 CI can't see the RED case. A fixed depth of 200 000 fails on every version. It adds no measurable time: the whole module runs in 0.17–0.67 s.(Change it in both tests.) With this change:
main-src: RED on all 5, exactly the 2 new tests..._in_libraries_raises_value_errorand the L146 mutant by..._api_responses_are_cli_errors_...All runs used
-Bwith__pycache__cleared. A stale.pycfrom two same-size mutants written within the same second gave me one misleading result before I did that.2. Another release-metadata decode in the same flow still leaks
RecursionError.publish_releasealso decodes the archive'sweb-release.json:metadata = json.loads(archive.read("web-release.json")). That file is downloaded release metadata too, and nothing catches this decode. To test it, I made a release whoseweb-v1.ziphas a matching size and sha256 digest and a 200 000-deepweb-release.json, then calledmain(["--build", root, "--release"]):RecursionError(escapesmain(), rc 1, traceback). Temporary staging is cleaned up andweb/keep.txtis preserved.Web converter does not match the selected releaseThe same helper fixes it.
json.loadreads bytes from the zip member, just asjson.loads(archive.read(...))did:With this change the probe gives rc 2
Invalid release metadata: maximum recursion depth exceeded…on 3.9.6/3.13, and…Stack overflow…on 3.15. There is no traceback, the site is untouched, and the root contains onlyweb/. The existing suite stays OK on 3.9.6/3.13/3.15. A regression test needs a digest-matchingweb-<tag>.zipfixture. I can post that harness if useful. It is about 25 lines, built fromWEB_FILESand therequestpatch you already use.The
manifest = json.loads(... release.json ...)at L192 reads a filepublish_librariesjust wrote, so it can't be attacker-deep. I'd leave it out of scope.Other checks
merge-treeagainst upstreammaind4cb89300fis clean.build_web.py,test_build_web.pyandpackage_release.pyare unchanged onmainsince your base750cf6cf48.-j 8run failedmacos_guest_weak_importsonce. It passed in isolation, passed 15× repeated, and passed in 3 further full-j 8runs. It's a relinker test unrelated to this diff.check_conventions.py --base upstream/mainpasses.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T14:24:52Z.
Review: COMMENTED
Rechecked exact head
418cd0d37ee9011a70c4784c814eefcba42534d7, including the two issues raised in the thread. The regression depth is now 200,000 in both fixtures, andpublish_releaseroutes the archive’sweb-release.jsonthroughload_release. On this Linux/Python 3.11 host,python3 -m unittest tools.tests.test_build_webpasses 19 tests with 1 platform-dependent skip;git diff --check upstream/main...HEADandpython3 tools/check_conventions.py --base upstream/mainpass. I copied the current test file into a disposable worktree at current main and ran the three new regressions against main’sbuild_web.py; all three fail with uncaughtRecursionError, including the nested archive metadata case. This confirms the tests are sensitive to the fix locally. The current hosted relinker matrix and labels are still pending, so I am not approving yet.Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T14:26:52Z.
Review: APPROVED
Re-checked head
418cd0d37eon macOS 26 arm64 (py3.9.6 / 3.13 / 3.14). Both points from my earlier review are addressed.python3 -B -m unittest tools.tests.test_build_web: OK on all three (one platform skip on 3.9.6).ReleaseMetadataTestsfinishes in under 1 s.main'sbuild_web.pyunder the head tests: exactly the 3 new tests ERROR with uncaughtRecursionErroron 3.9.6 and 3.14. At depth 200,000 the fixtures now fail on every Python, not only 3.9.json.load/json.loads. Every one is killed by its own test, on both 3.9.6 and 3.14:publish_librariesAPI response →..._libraries_raises_value_errorpublish_releaseAPI response →..._api_responses_are_cli_errors_without_site_changesweb-release.json→..._web_release_metadata_is_cli_error_without_site_changesload_release→ all 3 RED.check_conventions --base upstream/main: pass.git merge-treeagainstmain446bd8776c: clean.tools/tests/test_build_web.py.build_web.pyitself auto-merges. Whichever lands second needs a trivial rebase of the test file.Approving.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T20:29:09Z.
Review: APPROVED
Re-checked — new head, looks good
The exact head still handles recursion failures at the release JSON decode boundaries, and #12488 now explicitly depends on this PR with a clean combined merge preview.
What I ran
418cd0d37ee9011a70c4784c814eefcba42534d7; upstream base:319621ba2e578bd053b0baba2877fe70520e0737.python3 -m unittest tools.tests.test_build_web— 19 tests passed, 1 existing platform-dependent test skipped.git diff --check upstream/main...refs/review/pr-12446-current— passed.git merge-tree --write-tree upstream/main refs/review/pr-12446-current— clean, treef88a86fe0910dc67f60c7e06704e3fa3df4767cb.git merge-tree --write-tree refs/review/pr-12446-current refs/review/pr-12488-current— clean, tree38c0808d8419e822cdbe6778496952ac1283564a.Results
test_build_webTest output
Negative control
Not rerun in this follow-up. The exact-head review history records base-parser negative controls for all three JSON decode regressions; I reran the current-head focused test module here.
Findings
Blocking
None found.
Non-blocking
The hosted macOS relinker jobs remain queued, and the workflow skips product and specialized tests. The exact-head Python suite passes locally; I did not run a full native build or browser/WASM integration.
Sources
Depends on: #12446Not verified
I did not run Windows/macOS locally, the native full project build, browser/WASM integration, or product tests. The macOS hosted jobs were queued when checked.
To get this to a good state
No changes are required for this review. #12488 records #12446 as its prerequisite; I can rerun these checks if either head changes.
Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-29T06:30:14Z.
Review: COMMENTED
Reviewed
418cd0d37ee9011a70c4784c814eefcba42534d7againstacd13871affe9bb42bb4b59bfeb99778c816d3a8. All three release-metadata JSON entry points translate decoder recursion failure into the existing ValueError/CLI-error handling before publishing output. No actionable finding in this scoped review.Windows/Python 3.11 validation: head 18 passed, 1 skipped; baseline 15 passed, 1 skipped. The three new deep-metadata controls raise uncaught RecursionError with old production and pass with the fix, including preservation of the existing site. Network responses and archives are test fixtures; no site or release was published. One platform permission case is skipped.
Publication-time checks: merge conflict with main. Please complete these checks before final approval; this status alone is not a demonstrated implementation defect.