smh_groom: cap zlib inflation, validate bounds/args/polylines, and harden CLI guards (SMH-GROOM-VALIDATION-HARDENING) #1509
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1509"
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 ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T02:47:53Z.
Claimed in the coordination issue as: SMH-GROOM-VALIDATION-HARDENING (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7151063354)
What and why
Hardens
tools/smh_groom.pyagainst malformed inputs, unbounded zlib inflation, invalid API/CLI arguments, and unsafe output paths:inflate_stream,_read_zlib_resource,read_resource):inflate_streampreviously calleddecoder.decompress(chunk)with nomax_length, allowing a single 64 KiB compressed chunk to expand arbitrarily in memory beforelen(out) > MAX_INFLATE_BYTESwas checked. It now passesmax_length=remaining + 1, checksdecoder.unconsumed_tail, supports amax_bytesoverride (resolvingMAX_INFLATE_BYTESdynamically when omitted), and rejects negative orbooloffsets._read_zlib_resourcerejects declared GPU buffer sizes aboveMAX_INFLATE_BYTESupfront, caps cumulative multi-chunk GPU inflation atMAX_INFLATE_BYTES, and rejects zero-progress / empty zlib chunks instead of looping indefinitely.parse_system_page):NaN/±Infinbox_min(+0x30) andbox_max(+0x40) withGroomError(preserving finite±FLT_MAXchild-rig sentinels in+0x50..+0x6f), preventing downstreamValueErrorinto_glbor invalid JSON ininspect --json.load_groom,main):export-glbnow usesreport_paths.same_report_path(args.path, args.output)(covering symlinks, hard links, case-folding volumes, and non-existent aliases) and rejects an output directory upfront before loading the input;load_groomalso rejects directories cleanly withGroomError.Groom.seed,scatter,to_glb,_parse_classes,_parse_positive_float):boolvalues (False/Truepreviously passedin (0, 1)andintchecks) inseed,scatter, andto_glb.density_scaleas finite and non-negative (even whencount=0ormax_accepted <= 0), and avoidsOverflowErrorin_f32(float(c) * ds32)for large finitedensity_scale >= 1.0while preserving bit-exact float32 thresholds for0 < density_scale < 1.guide_radius/strand_radius(in bothto_glband CLI--guide-radius/--strand-radius), non-negativemax_strands, positivevertex_budget, stringup_axis, and deduplicatesclassesinto_glbsoclasses=(0, 0)does not emit duplicate strand primitives._parse_classesnow raisesargparse.ArgumentTypeErrorinstead of rawValueErroron non-integer tokens like--classes fooor--classes 0,.livevalidation (build_tubes,build_ribbons,build_lines):livelengths, invalidradius/width/tip, andboolsideswithGroomErrorinstead of silently shifting indices or throwingIndexError.run_census,main):run_censusvalidateslimit >= 1(non-bool) for direct Python callers and catchesstruct.error/OverflowErrorper resource so one corrupt file does not abort a multi-archive census.inspect --json,census --json, andexport-glbJSON output passallow_nan=False.Tested
python3 -I tests/test_smh_groom.py -v: 30/30 OK (22 existing + 8 new tests inValidationHardeningTests).main:tools/smh_groom.py: all 8 new tests inValidationHardeningTestsfail (FAILED (failures=16, errors=10)).python3 -I tests/test_text_write_line_endings.py: 3/3 OK.python3 -I tests/test_report_paths.py: 22/22 OK.python3 -I scripts/check_no_game_data.py tools/smh_groom.py tests/test_smh_groom.py: clean.python3 -m compileall -q tools/smh_groom.py tests/test_smh_groom.py: clean.GPUs tested: n/a (pure Python stdlib tool, synthetic unit tests only, no GPU or game data)
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a — no translator rule changes)Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T02:48:05Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Imported from ubiquitarianism/leonida. Originally posted by ytsodacan on 2026-11-25T03:34:12Z.
[KEEP]
tools/smh_groom.pyandtests/test_smh_groom.py(+434/-35), mergeable, and no other PR touchessmh_groom.MAX_INFLATE_BYTESwith exact-boundary and +1 cases, negative/bool offsets, non-finite bounding boxes, no-progress empty chunks).change-scopeandno-game-dataare still pending, so there is no green signal yet.Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-25T07:45:16Z.
Independent verification (native Windows, Python 3.11.9 — stdlib-only so representative): diff vs merge-base reviewed; all claimed hardening present —
inflate_streamdecompress cap + unconsumed-tail check,MAX_INFLATE_BYTESwith zero-progress rejection, non-finite bbox rejection, dir rejection forload_groom,same_report_pathfor export-glb, bool/int/float validation, strictallow_nan=FalseJSON. Tests:test_smh_groom.py30/30,test_report_paths.py22 OK (1 skip),test_text_write_line_endings.py3/3, compileall clean. AI-assisted verification.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T14:42:58Z.
Red/green:
pytest tests/test_smh_groom.pyfails on main (26 failed, 23 passed, 36 subtests passed) and passes on heada049209a73merged with main (30 passed, 92 subtests passed).Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main
d48a957bbin GitHub Actions: no new failure.AI-assisted (Claude Code, Claude Opus 5.5)