[GH-ISSUE #542] getMimeType returns text/plain for binary files (.zip, .exe, .wasm, .sqlite, etc.) #272

Closed
opened 2026-06-05 17:21:23 -04:00 by yindo · 0 comments
Owner

Originally created by @ixchio on GitHub (May 17, 2026).
Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/542

getMimeType() in backends/utils.ts defaults to "text/plain" for any extension not in the MIME_TYPES map. The map only covers images, audio, video, and PDFs — no text/code extensions either, everything just falls through to the default.

The problem is isTextMimeType("text/plain") returns true, so binary files get treated as text across the board:

  • grep searches through .zip, .exe, .wasm, .sqlite, .pyc, .class, .jar files and returns garbage matches
  • read_file splits binary content on \n and paginates it as "lines"
  • StateBackend.write() passes binary data through createFileData() as text
  • StateBackend.glob() reports file sizes from .content.length on garbled strings
// backends/utils.ts line 748-751
export function getMimeType(filePath: string): string {
  const ext = path.extname(filePath).toLocaleLowerCase();
  return MIME_TYPES[ext] || "text/plain";  // <-- this default is wrong
}

Every caller that does if (!isTextMimeType(mimeType)) { skip } — like grepSearchFiles, grepMatchesFromFiles, etc. — never skips binary files because they all come back as text/plain.

The default should be "application/octet-stream". isTextMimeType already returns false for it.

Originally created by @ixchio on GitHub (May 17, 2026). Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/542 getMimeType() in backends/utils.ts defaults to "text/plain" for any extension not in the MIME_TYPES map. The map only covers images, audio, video, and PDFs — no text/code extensions either, everything just falls through to the default. The problem is isTextMimeType("text/plain") returns true, so binary files get treated as text across the board: - grep searches through .zip, .exe, .wasm, .sqlite, .pyc, .class, .jar files and returns garbage matches - read_file splits binary content on \n and paginates it as "lines" - StateBackend.write() passes binary data through createFileData() as text - StateBackend.glob() reports file sizes from .content.length on garbled strings ```ts // backends/utils.ts line 748-751 export function getMimeType(filePath: string): string { const ext = path.extname(filePath).toLocaleLowerCase(); return MIME_TYPES[ext] || "text/plain"; // <-- this default is wrong } ``` Every caller that does `if (!isTextMimeType(mimeType)) { skip }` — like grepSearchFiles, grepMatchesFromFiles, etc. — never skips binary files because they all come back as text/plain. The default should be "application/octet-stream". isTextMimeType already returns false for it.
yindo closed this issue 2026-06-05 17:21:23 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#272