Skip to content

fix: enforce size limit on individual files in build_bundle() - #3911

Open
Quratulain-bilal wants to merge 3 commits into
github:mainfrom
Quratulain-bilal:fix/bundle-unbounded-read
Open

fix: enforce size limit on individual files in build_bundle()#3911
Quratulain-bilal wants to merge 3 commits into
github:mainfrom
Quratulain-bilal:fix/bundle-unbounded-read

Conversation

@Quratulain-bilal

Copy link
Copy Markdown
Contributor

Problem

build_bundle() called read_bytes() without any size guard. A single large asset file could exhaust memory.

Fix

Enforce MAX_ZIP_MEMBER_BYTES (10 MiB) limit before reading each file.

Testing

  • Verified normal files are packaged correctly
  • Verified oversized files are rejected

@Quratulain-bilal
Quratulain-bilal requested a review from mnriem as a code owner July 31, 2026 12:57

@mnriem mnriem left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please resolve conflicts

build_bundle() called read_bytes() without any size guard. A single
large asset file could exhaust memory. Enforce MAX_ZIP_MEMBER_BYTES
(10 MiB) limit before reading.
Enforce MAX_ZIP_MEMBER_BYTES (10 MiB) limit before reading each file
via os.fstat() on the same file descriptor used for reading, avoiding
a TOCTOU gap between stat() and read_bytes().

Add regression tests: oversized file (>limit) is rejected, file at
exact limit is accepted.

Co-authored-by: GitHub Copilot (model: mimo-v2.5-free, supervised)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds per-file size enforcement when building bundle archives.

Changes:

  • Rejects files exceeding the 10 MiB member limit.
  • Adds oversized and boundary-size tests.
Show a summary per file
File Description
src/specify_cli/bundler/services/packager.py Adds file-size validation before archive writes.
tests/unit/test_bundler_packager.py Tests rejection and exact-limit acceptance.

Review details

馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment on lines 101 to 105
if st.st_size > MAX_ZIP_MEMBER_BYTES:
raise BundlerError(
f"Bundle file {arcname} exceeds {MAX_ZIP_MEMBER_BYTES}-byte limit"
)
archive.writestr(info, fh.read())
fstat() is only a snapshot; another process can append to the file after
the check. Read MAX_ZIP_MEMBER_BYTES + 1 bytes and validate the length
so the limit cannot be bypassed by a concurrent writer.
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.

3 participants