Skip to content

tooling/libpng-oracle: expose bKGD/sBIT and a warning count so ancillary-chunk acceptance is oracle-testable #502

Description

@justin13888

Summary

libpng_oracle::decode returns pixels and IHDR fields only, and its warning callback is a no-op with png_set_benign_errors(png, 1). So when libpng rejects and drops an ancillary chunk — a bKGD whose length does not match the colour type, an sBIT entry past the depth, an index past the palette — the oracle cannot tell: the decode succeeds, the pixels match, and nothing records that the chunk was discarded.

PR #485 fixed the encoder emitting exactly such chunks (bKGD/sBIT shaped for the colour type the caller set rather than the one the race wrote). Its tests had to assert the emitted payload against libpng's acceptance rules transcribed from pngrutil.c, plus a libpng decode of the file — an exact-byte test standing in for the differential one the crate's authority row calls for.

Proposal

In tooling/libpng-oracle/src/lib.rs:

  • DecodedImage gains bkgd: Option<Vec<u8>> and sbit: Option<Vec<u8>>, read via png_get_bKGD / png_get_sBIT after png_read_info, serialised in the chunk's own byte layout so a test compares them to what the encoder wrote;
  • DecodedImage gains warnings: usize (or Vec<String>), counted in warn_callback — benign errors route through it under png_set_benign_errors, so a dropped chunk becomes observable as "libpng warned".

Then crates/gamut-png/tests/ancillary_colour_type.rs can assert decoded.bkgd == read_chunk(png, b"bKGD") and decoded.warnings == 0, which is the differential claim.

Why not in #485

tooling/libpng-oracle was outside that PR's manifest; the review finding was repaired with the strongest test constructible inside it, and this is the remainder.

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