Skip to content

Conversation

@0xsatoshi99
Copy link

@0xsatoshi99 0xsatoshi99 commented Dec 9, 2025

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:

elif data[:4] == b'\x00\x00\x00\x1c' or data[:4] == b'\x00\x00\x00\x20':
    return ".mp4"

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 ftyp signature at offset 4 (the standard location per ISO base media file format):

if len(data) >= 8 and data[4:8] == b'ftyp':
    return ".mp4"

Changes

Bug Fix

  • MP4 detection: Use ftyp-based detection instead of hardcoded box sizes
  • JPEG detection: Improved with 3-byte signature (FF D8 FF)
  • Length checks: Added bounds checking to prevent index errors on short data

New Format Support

Category Formats Added
Images GIF, BMP, TIFF, HEIC/HEIF, AVIF
Video MOV, 3GP, AVI (+ improved MP4)
Audio MP3, WAV, FLAC, OGG, M4A

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.

  • Verification (gas/verification/c2pa_verification.py)
    • Format detection (_detect_format):
      • Switch to ftyp-based parsing for ISO-BMFF formats (MP4/M4A/MOV/3GP/HEIC/AVIF) with brand-specific mapping.
      • Add detection for additional formats: GIF, BMP, TIFF, AVI, WebM/MKV, MP3, WAV, FLAC, OGG.
      • Improve JPEG detection to 3-byte signature and add length/bounds checks.
      • Expand docstring and return .bin for unknowns.

Written by Cursor Bugbot for commit 13ab63d. This will update automatically on new commits. Configure here.

- Fix MP4 detection by checking for 'ftyp' at offset 4 instead of hardcoded box sizes
- Add HEIC/HEIF and AVIF image format detection
- Add GIF, BMP, TIFF image format detection
- Add MOV, 3GP, AVI video format detection
- Add MP3, WAV, FLAC, OGG, M4A audio format detection
- Add length checks to prevent index errors on short data
- Improve JPEG detection with 3-byte signature
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on December 24

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

- Merge all ftyp-based format detection (HEIC, AVIF, M4A, MOV, 3GP, MP4) into single block
- Remove duplicate unreachable M4A detection code
- Ensures M4A files are correctly identified instead of falling through to MP4
@0xsatoshi99
Copy link
Author

@dylanuys Can you plz check this PR and give me your feedback? Thanks.

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