mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:50:52 +01:00
[PR #1509] smh_groom: cap zlib inflation, validate bounds/args/polylines, and harden CLI guards (SMH-GROOM-VALIDATION-HARDENING) #1538
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1538
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1509
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/smh-groom-hardening📝 Commits (1)
a049209smh_groom: cap zlib inflation, validate bounds/args/polylines, and harden CLI guards📊 Changes
2 files changed (+434 additions, -35 deletions)
View changed files
📝
tests/test_smh_groom.py(+293 -0)📝
tools/smh_groom.py(+141 -35)📄 Description
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)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.