Skip to content

Release wheel check: refuse extra directory entries and over-cap wheels, hash members as they are read, and catch RecursionError in the index checks (opensoft/openRepoTools#352 items 1 to 3) - #23

Merged
brettheap merged 4 commits into
mainfrom
fix/352-release-wheel-checks
Nov 10, 2026
Merged

brettheap merged 4 commits into
mainfrom
fix/352-release-wheel-checks

Conversation

@brettheap

@brettheap brettheap commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Lane: openRepoTools-3
Claim: opensoft/openRepoTools#352 (comment)

Fixes items 1 to 3 of opensoft/openRepoTools#352: the release wheel and index checks in .github/workflows/release.yml, from sourcery-ai's threads r4506270224, r4506270229 and r4506270238 on #12. Item 4 is not here: it waits for the open spec PR that edits 006's workflows.md.

What each fix does

  1. Directory entries. The wheel check's inventory dropped every name ending in /, so an extra directory entry was never seen. It now keeps them. A directory entry is allowed only where it is a parent directory of a file the wheel may hold (a tracked module, the stamp, a force-included payload file, or one of the five .dist-info names). Any other is refused with a named ::error:: line. hatchling 1.27.0, the pinned backend, writes no directory entry: a wheel built from this repository's HEAD with it lists 32 members and none, and passes the check, so a normal release is not refused.
  2. Memory. The read loop kept every member's bytes until the end. Now:
    • The members' declared file_size values are summed before anything is read, and a wheel over MAX_UNCOMPRESSED (256 MiB; today's wheel declares about 3.6 MB, so the cap is some seventy times that) is refused unread with a named ::error:: line.
    • Only STORED and DEFLATED members are read. Any member in another compression method is refused by name before any member is read, as NAME in the wheel cannot be read (compression method N, ...). The reason: CPython's zipfile decompresses BZIP2 and LZMA members with no limit and cuts the result to the declared size afterwards, so for them the declared size, and so the cap, bounds nothing. hatchling 1.27.0 writes method 8 (DEFLATED) only: a wheel built with it has methods [8] and passes.
    • A STORED or DEFLATED member is read in 1 MiB chunks and hashed, and its bytes are dropped. zipfile returns no more than such a member declares, so memory is one chunk plus the three members kept whole (the stamp, METADATA and entry_points.txt, which the check parses), and the cap bounds those three.
    • The byte-for-byte comparisons with the commit's blobs (payload files, modules, licenses/LICENSE) compare sha256 digests. Every existing check keeps its meaning and its message.
  3. RecursionError. A deeply nested index answer made json.loads raise RecursionError, which none of the four handlers named, so the step ended in a traceback. It is now in the exception tuple of each of the four handlers (the empty-index check and the served check, in the TestPyPI and the PyPI job), so the step ends with its named ::error:: refusal.

Tests added (tests/test_release_workflow.py)

  • Four wheels with a directory entry the wheel may not hold are refused with a named ::error:: line (one with nothing under it, one that only starts a parent's name, one below the payload with no file, one of another version's .dist-info), and a wheel with every parent directory listed passes and prints what the wheel without them prints.
  • A wheel whose declared uncompressed total is over the cap is refused before any member is read, by one member declaring 512 MiB and by every member declaring 16 MiB (so it is the sum that counts). A bad CRC in the same wheel is never named, and the output is the one refusal line.
  • A BZIP2 member (valid), an LZMA member and a member in method 99 are each refused by name and method, and a bad CRC in the same wheel is never named, so no member was read first.
  • A 100,000-deep, balanced JSON answer gives the step's one named ::error:: line and no Traceback at each of the four index checks. Which line depends on the interpreter that runs the step: with RecursionError in it where json.loads raises it (the 3.12.3 used for the runs here), and "is not its JSON API's (TypeError: ...)" where it decodes the nested list (CI's CPython 3.15.2). The case probes the python3 the step runs and expects accordingly.
  • Before the fix, each refusing case failed and the pass case passed.

Review fix round

Lane 3's review of e7ec834 found item 2's bound false for BZIP2 and LZMA: a 2 KB BZIP2 member padded with 300 MB of zeros, declaring 4,322 bytes, passed that head and took about 600 MiB. With the method refusal the same wheel exits 1 naming the member at 36 MiB, and a DEFLATED one of the same shape passes at 36 MiB. The review's comment nits (three comment lines over 80 columns, two unqualified #278, a split reference) are fixed too. Two things the review logged for later are not in this PR: a member's bytes past its declared size, and the TestPyPI fetch step's json.load.

CI fix

CI at 8510181 failed on the four nested-JSON cases only: CI runs CPython 3.15.2, where json.loads of the nested answer decodes a list instead of raising RecursionError, so the step refused its wrong shape with its named line. That is the right behaviour, so release.yml is unchanged. The test now follows the interpreter (see Tests added).

Narrow run

TMPDIR=/tmp XDG_STATE_HOME=/tmp/l3-352 timeout 3600 bash tests/run.sh -k 'test_release_workflow or repo_hygiene', run once on the committed tree of the head (b69a8b1) with the pinned openRepoShape submodule initialized: 797 passed, 18 skipped, 3255 deselected in 58.04s, exit 0. The earlier heads' runs: d23268d, 797 passed, 18 skipped, 3255 deselected in 59.76s; 8510181, 797 passed, 18 skipped, 3255 deselected in 59.93s; e7ec834, 794 passed, 18 skipped, 3255 deselected in 75.38s (0:01:15). The head b69a8b1 only splits one composite assertion in the tests' a_directory_entry into two (SonarCloud python:S9073).

release.yml still parses as YAML (PyYAML 6.0.3, four jobs).

This is a draft: it leaves draft only after lane 3's independent review, and it lands only on Brett's word.

🤖 Generated with Claude Code

…heel check, hash each member as it is read, and catch RecursionError in the index checks

Fixes items 1 to 3 of opensoft/openRepoTools#352, the sourcery-ai threads
on #12. Item 4 is not here.

1. Directory entries. The wheel check's inventory dropped every name ending
   in "/", so an extra directory entry in the release wheel was never seen.
   The inventory now keeps them: one is allowed only where it is a parent
   directory of a file the wheel may hold (a tracked module, the stamp, a
   force-included payload file, or one of the five .dist-info names), and
   any other is refused with a named ::error:: line. hatchling 1.27.0 writes
   no directory entry (a wheel built from HEAD with it lists 32 members and
   none), so a normal release still passes.

2. Memory. The read loop kept every member's bytes until the end. The
   members' declared file_size values are now summed before anything is
   read, and a wheel over MAX_UNCOMPRESSED (256 MiB, about seventy times
   today's 3.6 MB wheel) is refused with a named ::error:: line, unread.
   Each member is then read in 1 MiB chunks and hashed, and its bytes are
   dropped: only the stamp, METADATA and entry_points.txt, which the check
   parses, are kept whole. The byte-for-byte comparisons against the commit's
   blobs (payload files, modules, licenses/LICENSE) compare sha256 digests,
   and every existing check keeps its meaning and its message.

3. RecursionError. A deeply nested index answer made json.loads raise
   RecursionError, which none of the four handlers named, so the step
   ended in a traceback. It joins the exception tuple of each of the four
   handlers (the testpypi and pypi jobs' empty-index and served checks), so
   the step ends with its named ::error:: refusal.

tests/test_release_workflow.py: four refused directory entries (one that
only starts a parent's name among them), a wheel with every parent
directory listed that passes as the wheel without them does, a wheel over
the cap by one member and by the sum (refused unread: a bad CRC in the same
wheel is never named), and a 100,000-deep JSON answer at each of the four
index checks.

Lane: openRepoTools-3
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Configuration

Update the release wheel check to reject unexpected directory entries, enforce an aggregate uncompressed-size cap and supported compression methods before reading, and hash members incrementally while retaining only parsed files.

  • .github/workflows/release.yml L818-831, L856-873, L942-963 (+8 small edits)

Include RecursionError in the JSON refusal handlers for the empty-index and served checks in both release jobs.

  • .github/workflows/release.yml L1261-1264, L1317-1320 (+4 small edits)

Tests

Add wheel fixtures and checks for allowed and refused directory entries, over-cap wheels, and unsupported compression methods, including assertions that refusal happens before reading members.

  • tests/test_release_workflow.py L2090-2113, L2172-2184, L2415-2527 (+6 small edits)

Add interpreter-aware tests for deeply nested JSON answers across the four index checks, verifying a named refusal without a traceback.

  • tests/test_release_workflow.py L3826-3862, L4022-4026, L4096-4100 (+4 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

…D before reading, test RecursionError for itself, and fix the review's comment nits

Fix round for #23, on lane 3's review of
e7ec834 (items 1 to 3 of opensoft/openRepoTools#352).

1. The memory bound of item 2 held for STORED and DEFLATED members only.
   CPython's zipfile decompresses a BZIP2 or an LZMA member with no limit
   and cuts the result to the declared size afterwards, so a 2 KB BZIP2
   member padded with 300 MB of zeros declared 4,322 bytes, passed the
   256 MiB cap and the old check, and took about 600 MiB. The wheel check
   now refuses every member whose compression method is not STORED or
   DEFLATED, with "<name> in the wheel cannot be read (compression method
   N, ...)", before any member is read, beside the cap. With that member the
   peak is 36 MiB and the step exits 1 naming it. hatchling 1.27.0 writes
   method 8 only, so a real wheel still passes (re-checked on a wheel built
   with it: methods [8], 32 members, exit 0). The comment above the cap and
   the step's header say exactly what is bounded. lzma.LZMAError stays in
   the read loop's tuple, though no member reaches it now.

2. Three comment lines over 80 columns are rewrapped, and the two
   comments that read the unqualified issue references now say
   opensoft/openRepoTools#278 and opensoft/openRepoTools#352.

tests/test_release_workflow.py: a BZIP2 member, an LZMA member and a member
in method 99 are refused by their method and named, and a bad CRC in the
same wheel is never reported (so no member was read first). The nested
index answer is now 100,000 [ closed by 100,000 ], which is valid JSON, and
each of the four cases asks for RecursionError in the refusal's line, so a
plain ValueError no longer passes them. The split issue reference in the
NESTED comment is joined.

Lane: openRepoTools-3
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…r that runs the step: RecursionError up to Python 3.13, the wrong-shape refusal after

CI for #23 failed at 8510181 in tests-shard
(pytest-3) on the four nested-JSON cases only. CI runs CPython 3.15.2,
where json.loads of 100,000 balanced brackets no longer raises
RecursionError (CPython bounds the C decoder's recursion by stack depth
there): it decodes a nested list, and the step refuses its wrong shape with
its named line, "is not its JSON API's (TypeError: list indices must be
integers or slices, not str)". That is the right behaviour, so release.yml
is unchanged. On the 3.12.3 used here the same input raises RecursionError.

The expectation of those four cases (the empty-index and the served check,
in both upload jobs, ids unchanged) now follows the interpreter. The index
steps run the python3 on the step's PATH, which is not always
sys.executable (only the wheel check's heredoc runner uses that), so
nested_refusal probes that python3 with json.loads of NESTED: where it
raises, the case requires "(<the error>:" in the ::error:: line, as
"(RecursionError:" did; where it decodes the list, it requires "is not its
JSON API's". Either way each case still requires exit 1, no Traceback, and
that the whole output is the one named ::error:: line. NESTED stays
balanced, and a comment says why the expectation depends on the interpreter.

Lane: openRepoTools-3
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@brettheap
brettheap marked this pull request as ready for review November 10, 2026 03:13
@sourcery-ai

sourcery-ai Bot commented Nov 10, 2026

Copy link
Copy Markdown

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 5 days and 10 hours by commenting @sourcery-ai review. Upgrade to get a review now.

…h its own message (SonarCloud python:S9073)

SonarCloud's gate passed on #23 at d23268d and
reported one new MAJOR issue from it: python:S9073, "Split this composite
assertion into separate assertions", on a_directory_entry's change() in
tests/test_release_workflow.py. The one assert that held two conditions,
`entry.endswith("/") and entry not in members`, is now two: one that the
case's name ends in "/", and one that the entry is not already in the wheel,
each with its own message. Nothing else changes.

Lane: openRepoTools-3
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@sonarqubecloud

Copy link
Copy Markdown

@brettheap
brettheap merged commit 3460f5e into main Nov 10, 2026
15 checks passed
@brettheap
brettheap deleted the fix/352-release-wheel-checks branch November 10, 2026 12:00
brettheap added a commit that referenced this pull request Nov 10, 2026
…L names, name a bad TestPyPI answer in the fetch, and count the macOS rerun's lines in the contract's form (opensoft/openRepoTools#352 items 4 to 6) (#26)

Item 4 of opensoft/openRepoTools#352 and its follow-ups 5 and 6, from the sourcery-ai threads on release.yml's wheel and index checks (#12) and 006's macOS rerun (opensoft/openRepoTools-spec#11). Items 1 to 3 landed in #23.
- The build job's wheel check holds a wheel to the layout zipfile writes, from byte 0 to the end of its end record. Each member's local header repeats its central entry's fields, the members follow one another with nothing between them, and the central directory and end record end the file with no extra field or comment. Each member's data must give exactly its declared size and CRC-32. Bytes no member declares, a local header that disagrees with its central entry, a directory entry that holds bytes, and a name with a NUL byte are each refused in one ::error:: line (follow-up 5).
- The install job's TestPyPI fetch names an answer that is not TestPyPI's JSON in one ::error:: line instead of a traceback, and fetches nothing (follow-up 6).
- The macOS rerun counts only lines of the contract's exact form toward its 16, so a line naming another file, or carrying more after "(unchanged)", no longer counts (item 4).
- The review's fix round reads the last central record's name, extra field and comment lengths from the directory's own bytes. It ends a directory entry at a negative offset in an ::error:: line, not a traceback, and it names a name flagged UTF-8 that is not UTF-8 and a version needed to extract above 6.3.

Lane openRepoTools-3's independent review read READY at 5a175f3, with no MUST. Its two SHOULDs and its NIT 3 are fixed at e0e9278 with six new cases, each failing before the fix, and lane openRepoTools-3 checked that delta. All 14 checks are green at e0e9278, tested on main ecd1bce. It lands under Brett Heap's standing landing word for lane 3's own fixes, typed in lane 3's session on 2026-11-10.

Fixes opensoft/openRepoTools#352

Lane: openRepoTools-3
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant