fix: improve media format detection with proper ftyp-based MP4 detection #311
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.
Summary
Fixes incorrect MP4 format detection in C2PA verification by using proper ftyp-based detection instead of hardcoded box sizes. Also adds comprehensive support for additional media formats.
Problem
The previous implementation detected MP4 files by checking for specific ftyp box sizes:
This only catches MP4 files with ftyp box sizes of 28 or 32 bytes. Many valid MP4 files have different box sizes and would incorrectly return
.bin, causing C2PA verification to fail.Solution
Check for
ftypsignature at offset 4 (the standard location per ISO base media file format):Changes
Bug Fix
FF D8 FF)New Format Support
Testing
Manual verification with sample files of each format type.
Contribution by Gittensor, learn more at https://gittensor.io/
Note
Improves media format detection for C2PA verification using ftyp-based parsing and adds broad image, video, and audio format support with safer bounds checks.
gas/verification/c2pa_verification.py)_detect_format):ftyp-based parsing for ISO-BMFF formats (MP4/M4A/MOV/3GP/HEIC/AVIF) with brand-specific mapping.GIF,BMP,TIFF,AVI,WebM/MKV,MP3,WAV,FLAC,OGG..binfor unknowns.Written by Cursor Bugbot for commit 13ab63d. This will update automatically on new commits. Configure here.