[PR #9810] fix(read): enhance file validation with comprehensive magic byte chec… #13228

Open
opened 2026-02-16 18:18:05 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/9810

State: open
Merged: No


Fixes #9512

What does this PR do?

Improve validation against file signatures from Wikipedia's file signature reference to be more robust:

  • PNG: Validate full 8-byte signature (89 50 4E 47 0D 0A 1A 0A)
  • JPEG: Validate 3-byte start marker (FF D8 FF)
  • GIF: Check for GIF87a or GIF89a (6-byte format)
  • WebP: Validate RIFF...WEBP structure (12-byte check)
  • PDF: Validate PDF header (25 50 44 46)

Add comprehensive test coverage for invalid GIF and PDF files to ensure the robust validation catches misnamed/corrupted files across all formats.

How did you verify your code works?

https://github.com/user-attachments/assets/f9f71b60-4f9b-4428-a783-e426afa7522e

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/9810 **State:** open **Merged:** No --- Fixes #9512 ### What does this PR do? Improve validation against file signatures from [Wikipedia's file signature reference](https://en.wikipedia.org/wiki/List_of_file_signatures) to be more robust: - PNG: Validate full 8-byte signature (89 50 4E 47 0D 0A 1A 0A) - JPEG: Validate 3-byte start marker (FF D8 FF) - GIF: Check for GIF87a or GIF89a (6-byte format) - WebP: Validate RIFF...WEBP structure (12-byte check) - PDF: Validate PDF header (25 50 44 46) Add comprehensive test coverage for invalid GIF and PDF files to ensure the robust validation catches misnamed/corrupted files across all formats. ### How did you verify your code works? https://github.com/user-attachments/assets/f9f71b60-4f9b-4428-a783-e426afa7522e
yindo added the pull-request label 2026-02-16 18:18:05 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13228