-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(weixin): confirm the WEBP signature, not just the RIFF prefix #5285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -80,11 +80,17 @@ export function detectImageMime(data: Buffer): string { | |||||||||||||||||||||||
| if (data[0] === 0x47 && data[1] === 0x49 && data[2] === 0x46) { | ||||||||||||||||||||||||
| return 'image/gif'; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| // WebP is a RIFF container, so the "RIFF" prefix alone is not enough β WAV and | ||||||||||||||||||||||||
| // AVI share it. The bytes at offset 8-11 must spell "WEBP" to confirm the type. | ||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||
| data[0] === 0x52 && | ||||||||||||||||||||||||
| data[1] === 0x49 && | ||||||||||||||||||||||||
| data[2] === 0x46 && | ||||||||||||||||||||||||
| data[3] === 0x46 | ||||||||||||||||||||||||
| data[3] === 0x46 && | ||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] The WebP check accesses Consider adding an explicit guard:
Suggested change
β qwen3.7-max via Qwen Code /review |
||||||||||||||||||||||||
| data[8] === 0x57 && | ||||||||||||||||||||||||
| data[9] === 0x45 && | ||||||||||||||||||||||||
| data[10] === 0x42 && | ||||||||||||||||||||||||
| data[11] === 0x50 | ||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||
| return 'image/webp'; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] The old test used a 4-byte RIFF buffer which implicitly covered the short-buffer path. The replacement uses a full 12-byte header, so there's no longer a test asserting that a truncated RIFF buffer (< 12 bytes) falls through gracefully rather than crashing. Consider adding:
This locks in the graceful fall-through behavior so future refactors cannot silently break it.
β qwen3.7-max via Qwen Code /review