Feature: Add fast single-pass C2PA signing for BMFF, RIFF, and TIFF formats - 2x + signing speed#2010
Open
peekmoar wants to merge 2 commits into
Open
Feature: Add fast single-pass C2PA signing for BMFF, RIFF, and TIFF formats - 2x + signing speed#2010peekmoar wants to merge 2 commits into
peekmoar wants to merge 2 commits into
Conversation
Replace the standard 7-pass signing flow with a single-pass approach that reads the source once, writes the output once, computes the content hash simultaneously during the write pass, then seek-patches the signed JUMBF. Benchmarks show 2-4x speedup on large files: - BMFF (MP4): 3.77x faster (466ms -> 124ms on 277MB) - RIFF (WAV): 3.20x faster (81ms -> 25ms on 50MB) - TIFF: 2.05x faster (24ms -> 12ms on 24MB) New public API: - sign_bmff_fast() for MP4/HEIF/AVIF - sign_riff_fast() for WAV/WebP/AVI - sign_tiff_fast() for TIFF/DNG All three fall back to Builder::sign() for non-matching formats. Security hardening: - Bounded entry_count validation for stco/co64/iloc/saio boxes - IFD chain cycle detection (MAX_IFD_COUNT) - RIFF recursion depth limit (MAX_CHUNK_DEPTH) - Checked arithmetic for all offset patch operations - Input validation for all parsed fields from untrusted data 41 tests (21 unit + 20 integration), all passing.
39 issues found and fixed across 5 review passes: - Overflow-safe arithmetic (checked_add/checked_sub) throughout - Bounded allocations from untrusted BMFF/RIFF/TIFF fields - iloc/saio/stco/co64/tfra entry count validation against box size - Minimum box size validation before parsing - Runtime hash algorithm dispatch (DynHasher) instead of hardcoded SHA-256 - TIFF re-sign always appends fresh IFD (fixes orphaned chain bug) - Deterministic salting support for RIFF and TIFF - Missing tfra moof_offset patching for fragmented MP4 - Reserve size caching to prevent inconsistent signer behavior - No-panic feed() for library safety
bfd5cb7 to
c58c847
Compare
meta-codesync Bot
pushed a commit
to facebook/sapling
that referenced
this pull request
Apr 9, 2026
Summary: Replace dhruvmongia fork with peekmoar fork pointing to upstream PR contentauth/c2pa-rs#2010 for the O(2^N) manifest dedup fix. Uses git dependency instead of overlay per third-party Rust policy. After landing the upstream PR, bump c2pa to the release containing the fix and remove this patch entry. Reviewed By: dtolnay Differential Revision: D99923178 fbshipit-source-id: 27d0c2fb295cd5ff2be25d3584c17af2322c8206
meta-codesync Bot
pushed a commit
to facebookexperimental/rust-shed
that referenced
this pull request
Apr 9, 2026
Summary: Replace dhruvmongia fork with peekmoar fork pointing to upstream PR contentauth/c2pa-rs#2010 for the O(2^N) manifest dedup fix. Uses git dependency instead of overlay per third-party Rust policy. After landing the upstream PR, bump c2pa to the release containing the fix and remove this patch entry. Reviewed By: dtolnay Differential Revision: D99923178 fbshipit-source-id: 27d0c2fb295cd5ff2be25d3584c17af2322c8206
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes in this pull request
Summary
Test plan:
ffmpeg -f lavfi -i testsrc=duration=60:size=1920x1080:rate=30 -c:v libx264 /tmp/test_large.mp4
ffmpeg -f lavfi -i sine=frequency=440:duration=300 -ar 44100 /tmp/test_large.wav
ffmpeg -f lavfi -i testsrc=size=4096x4096 -frames:v 1 /tmp/test_large.tif
Checklist
TO DOitems (or similar) have been entered as GitHub issues and the link to that issue has been included in a comment.