Conversation
…enchmark regression Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
…2737317895825197
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
| if (bytes.length >= 5 && bytes[0] === 0x25 && bytes[1] === 0x50 && bytes[2] === 0x44 && bytes[3] === 0x46 && bytes[4] === 0x2d) { | ||
| detectedType = "application/pdf"; | ||
| } else if (bytes.length >= 8 && bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e && bytes[3] === 0x47 && bytes[4] === 0x0d && bytes[5] === 0x0a && bytes[6] === 0x1a && bytes[7] === 0x0a) { | ||
| detectedType = "image/png"; | ||
| } else if (bytes.length >= 3 && bytes[0] === 0xff && bytes[1] === 0xd8 && bytes[2] === 0xff) { | ||
| detectedType = "image/jpeg"; | ||
| } else if (bytes.length >= 8 && bytes[0] === 0xd0 && bytes[1] === 0xcf && bytes[2] === 0x11 && bytes[3] === 0xe0 && bytes[4] === 0xa1 && bytes[5] === 0xb1 && bytes[6] === 0x1a && bytes[7] === 0xe1) { | ||
| detectedType = "application/x-ole-storage"; | ||
| } else if (bytes.length >= 4 && bytes[0] === 0x50 && bytes[1] === 0x4b && bytes[2] === 0x03 && bytes[3] === 0x04) { | ||
| detectedType = "application/zip"; | ||
| } |
There was a problem hiding this comment.
MAGIC_NUMBER_MAP はマジックナンバーの定義を持ち続けていますが、実際の判定ロジックはこの if-else チェーンに移されました。将来の開発者が新しいファイルタイプを追加する際、MAGIC_NUMBER_MAP にエントリを追加しても、対応する if-else ブランチを追加しないと サイレントに検出スキップされます(MAX_MAGIC_SIZE の計算には使われるが、マッチングには使われないため)。
MAGIC_NUMBER_MAP の用途を MAX_MAGIC_SIZE のみに限定するか、コメントで両箇所の同期が必要であることを明示することを検討してください。
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/api/src/utils/file.ts
Line: 235-245
Comment:
**`MAGIC_NUMBER_MAP` との乖離リスク**
`MAGIC_NUMBER_MAP` はマジックナンバーの定義を持ち続けていますが、実際の判定ロジックはこの if-else チェーンに移されました。将来の開発者が新しいファイルタイプを追加する際、`MAGIC_NUMBER_MAP` にエントリを追加しても、対応する if-else ブランチを追加しないと **サイレントに検出スキップ**されます(`MAX_MAGIC_SIZE` の計算には使われるが、マッチングには使われないため)。
`MAGIC_NUMBER_MAP` の用途を `MAX_MAGIC_SIZE` のみに限定するか、コメントで両箇所の同期が必要であることを明示することを検討してください。
How can I resolve this? If you propose a fix, please make it concise.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merging this PR will not alter performance
Comparing Footnotes
|
Summary
Promotes
stagingintomain.stagingmainnpm run pr:promoteIncluded PRs
Compare
Greptile Summary
CodSpeed のパフォーマンス回帰を修正するため、
validateMagicNumbers内のマジックナンバー検出ループを、各シグネチャに対応するインライン if-else ブランチに展開しています。バイト比較のロジックは元の実装と完全に等価であり、機能的な問題は見当たりません。Confidence Score: 5/5
Important Files Changed
MAGIC_NUMBER_MAPが部分的にしか使われなくなる保守性の懸念が残る。Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[validateMagicNumbers] --> B[Read first MAX_MAGIC_SIZE bytes] B --> C{PDF signature match?} C -- Yes --> D[detectedType = pdf] C -- No --> E{PNG signature match?} E -- Yes --> F[detectedType = png] E -- No --> G{JPEG signature match?} G -- Yes --> H[detectedType = jpeg] G -- No --> I{OLE signature match?} I -- Yes --> J[detectedType = ole-storage] I -- No --> K{ZIP signature match?} K -- Yes --> L[detectedType = zip] K -- No --> M[return false] D & F & H & J & L --> N{MIME_COMPATIBILITY check} N -- mismatch --> O[return false] N -- match --> P{PPTX?} P -- Yes --> Q[hasZipEntry check] P -- No --> R{PPT?} R -- Yes --> S[hasOleStream check] R -- No --> T[return true] Q & S --> TPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "Merge pull request #495 from Hiroki-org/..." | Re-trigger Greptile