Skip to content

PhotoRec: add configurable minimum image filters - #214

Open
AIVensk wants to merge 1 commit into
cgsecurity:masterfrom
AIVensk:bounty/167-image-minimums
Open

AIVensk wants to merge 1 commit into
cgsecurity:masterfrom
AIVensk:bounty/167-image-minimums

Conversation

@AIVensk

@AIVensk AIVensk commented Sep 28, 2026

Copy link
Copy Markdown

Summary

Addresses #167 with independent minimum JPEG/PNG width, height, pixel count and final file size settings. All four default to zero (disabled), and equality passes.

  • Adds editable values to PhotoRec’s Options screen and strict decimal batch options image_min_width, image_min_height, image_min_pixels, and image_min_bytes.
  • Saves/restores all four values through the existing session format.
  • Probes image metadata before creating an output file, reusing the header buffer where possible. Ordinary below-minimum images are skipped before any recovery output is opened.
  • Handles JPEG markers beyond the initial 64 KiB buffer, including progressive JPEG, large APP/EXIF segments and deferred DNL heights. Embedded thumbnail markers are not interpreted as parent dimensions.
  • Rechecks limits against the reconstructed image after native validation/trimming. Non-image formats retain their existing behavior. A format-probe table allows additional formats without changing the options or recovery adapters.

Example:

photorec /d recovered /cmd image.dd options,image_min_width,640,image_min_height,480,image_min_pixels,307200,image_min_bytes,10240,search

Recovery behavior and limits

Preflight uses a 4 KiB cache and bounds work to 16 MiB of reads / 65536 markers or chunks. It stays within the current source extent, limits ext2 preflight before indirect blocks, and leaves brute-force reconstruction to the final stream check. APP2 MPF data does not use the first JPEG EOI as the whole multi-picture size.

Unknown or corrupt dimension metadata preserves normal recovery; it is not treated as zero dimensions. Fragmented/incomplete images or probe-budget exhaustion can therefore require output writes before final rejection, and unknown dimensions are retained according to existing recovery behavior. The byte minimum is checked against the final native recovery size. These behaviors are documented in the manual and test README.

QPhotoRec initializes the added options to disabled; its GUI does not gain controls in this change.

Validation

Built testdisk, photorec, fidentify, and qphotorec locally with GCC, ncurses and libjpeg support. Existing compiler warnings remain; the new format parser also compiles with -Wall -Wextra -Werror.

Reproducible test commands are in tests/README.md:

  • C parser/options/session round-trip checks, including unsigned overflow and malformed arguments.
  • Format-probe cases for SOF variants, long APP metadata, fake embedded markers, byte stuffing/restarts, DNL, MPF, PNG CRCs, large dimensions and short inputs.
  • Actual CLI error checks and 15 interactive ncurses assertions.
  • Nine recovery integration tests covering threshold boundaries, PNG/JPEG/progressive JPEG, SOF beyond 64 KiB, mixed rejected/accepted files, unaffected BMPs, and default recovered file contents matching an untouched upstream build byte-for-byte. Linux output-open interception verifies the ordinary rejected fixtures never reach recovery fopen.

All fixtures are synthetic and all recovery tests use temporary files, not physical disks.

Developed with AI assistance in Codex. The validation described above was run locally on Linux.

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