Skip to content

gamut-dng: bound DngEncoder::with_c2pa_reserved's length, as gamut-tiff and gamut-avif do #552

Description

@justin13888

DngEncoder::with_c2pa_reserved(len) is an infallible builder (crates/gamut-dng/src/encoder.rs:214), and the length it stores reaches vec![0; len] unchecked at encoder.rs:237. Past isize::MAX that panics with a capacity overflow instead of returning, so a caller's number turns into a panic out of a library path.

The identical defect was fixed this round in the other two container crates of the C2PA epic (#239), both with the same shape — refuse at the encode, since the builder cannot fail, before the reservation is allocated:

  • gamut-avif: refuses a length below the 8-byte JUMBF box header and one the framing cannot hold.
  • gamut-tiff: refuses below the store minimum (8, or 9 in BigTIFF) and above the smaller of what a buffer holds (isize::MAX) and what the container's count and offset words describe (u32::MAX classic, 64-bit BigTIFF).

gamut-dng already shares gamut_ifd::c2pa's placement rules with gamut-tiff, so the same two bounds apply to it unchanged — a DNG is a TIFF/EP profile over the same IFD container. Filed rather than fixed in place because crates/gamut-dng/ belongs to a different, unmerged pull request (#508 / #442), and reaching into it from the gamut-tiff branch would cross a pull-request boundary.

Suggested acceptance: a len of usize::MAX (and one past each variant's own bound) is refused as Error::InvalidInput on every encode entry point, asserted on the message rather than is_err, with no allocation and no panic; the three crates' refusals say the same thing about the same input.

Refs #239, #442, #446.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions