Skip to content

Never crash: Refuse an ERF or MEF whose raw strip runs past the file (#2119) - #2155

Open
endthestart wants to merge 5 commits into
storytold:mainfrom
endthestart:fix/2119-erf-mef-strip-length
Open

endthestart wants to merge 5 commits into
storytold:mainfrom
endthestart:fix/2119-erf-mef-strip-length

Conversation

@endthestart

@endthestart endthestart commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

The ERF and MEF readers picked the raw IFD by checking that StripByteCounts matched width × height, but they never checked that the file actually holds that many bytes. A tiny file declaring a huge frame got through, and the header probe then allocated the full sample buffer to measure white balance, so a few KB could cost gigabytes during import.

Now both decoders refuse a strip that runs past the end of the file before they size anything from it.

I added a test for each format that takes a small valid sample, rewrites its height and strip length to claim a much larger frame, and checks that probe_info and decode return a Corrupt error. Both failed before the change. Let me know if you'd rather fix it another way. Thank you.

Fixes #2119

Summary by CodeRabbit

  • Bug Fixes
    • Epson ERF and Mamiya MEF files with raw strips extending beyond the file are now reported as corrupt during import. Probe results still recognize these formats, while attempts to inspect or decode the affected files return a corruption error. This prevents incomplete strip data from being treated as valid during import.

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 6d9d5eb and ab3f6af.

Files selected for processing: 2
  • crates/raw/src/vendor/mef.rs
  • docs/whats-new.md
Files skipped from review as they are similar to previous changes: 1
  • docs/whats-new.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

ERF and MEF decoding now rejects raw strips when the available bytes do not match the declared length. Regression tests cover oversized strip declarations. The release notes describe the change.

Changes: Raw strip validation

Layer / File(s) Summary
ERF and MEF strip length checks
crates/raw/src/vendor/erf.rs, crates/raw/src/vendor/mef.rs, docs/whats-new.md
Both decoders return corruption errors when the first strip is unavailable or its byte length differs from its declared length. Regression tests verify that format probing succeeds while probe_info and decode return corruption errors for oversized declarations. The release notes describe the change.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

Possibly related PRs

Suggested reviewers: dylanmtaylor, fredapps

Merge Risk: Minimal · up to ab3f6

ERF and MEF imports now reject incomplete raw strips. No outstanding issue in the supplied evidence prevents merging after normal checks.

Architecture risk: Low · up to ab3f6

The change affects 2 systems.

Changed systems: crates, docs

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — crates (service) was modified; 2 changed files map to changed impact.
  • observed — docs (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in crates/raw/src/vendor/erf.rs: The decoder now requires the first strip to be readable and its actual byte length to equal the declared chunk length; otherwise it returns a corruption error. Previously, any readable first strip was accepted without checking that length.
  • observed — Modified behavior in crates/raw/src/vendor/erf.rs: Adds the test helper declare, which rewrites the raw IFD’s image height, rows per strip, and strip byte count in the TIFF bytes, handling both short and long tag values.
  • observed — Modified behavior in crates/raw/src/vendor/erf.rs: Adds a regression test with a strip declared as 2,000 rows and 64,000 bytes despite having only the original two-row data. It checks that ERF probing succeeds, while probe_info and decode return RawError::Corrupt.
  • observed — Modified behavior in crates/raw/src/vendor/mef.rs: The decoder now requires the bytes obtained for the first strip to match its declared length exactly; missing or short strip data returns a corruption error before sample-buffer allocation.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: ERF and MEF decoding now refuses a raw strip that extends past the end of the file. The raw summary confirms that both erf.rs and mef.rs reject such strips with a Corr…
Linked Issues check Passed Issue #2119 is closed and completed, so it supplies historical context only. No active directly linked issue supplies coding requirements for this pull request.
Out of Scope Changes check Passed The ERF and MEF strip-bound checks, regression tests, and the related whats-new entry address the reported raw-strip allocation problem. The available summary shows no unrelated change.
Full details: Title check

Explanation

The title names the main change: ERF and MEF decoding now refuses a raw strip that extends past the end of the file. The raw summary confirms that both erf.rs and mef.rs reject such strips with a Corrupt error, and that the docs and tests cover the same behavior. The title's '#2119' reference matches the linked issue, but the PR objectives cite #2155 in the description, a numbering mismatch that does not affect the title's relevance. The title is 76 characters, slightly above a short single-line ideal, but it is specific and clear.

Full details: Docstring Coverage

Explanation

Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

emmertex added a commit to emmertex/lightcraft-classic that referenced this pull request Oct 22, 2026
…st the file

Port of storytold#2155: the header probe sized its sample buffer
from the declared strip length; a short strip is now a Corrupt error.
Tests adapted to the fork's arithmetic lint.

Sources: own design (upstream PR).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
emmertex added a commit to emmertex/lightcraft-classic that referenced this pull request Oct 22, 2026
Upstream storytold#2155: refuse ERF/MEF whose raw strip runs past the file
…p-length

# Conflicts:
#	crates/raw/src/vendor/mef.rs

This branch has not been deployed

No deployments
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.

ERF/MEF: the raw IFD is accepted on its declared StripByteCounts, and the import probe allocates up to 2 GiB

1 participant