You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mime.detect treats truncated multi-byte UTF-8 as text/plain #56183
In \packages/core/src/mime.ts, \isBinary\ uses \decoder.decode(chunk, { stream: true })\ without a final flushing call. If a buffer ends with an incomplete multi-byte UTF-8 sequence (e.g. cut-off \
Thanks for the report. I could reproduce this: on v2.0.31 and on the latest dev (0a03b4b), Mime.detect returns text/plain for [0x61, 0x62, 0xC3] and [0x61, 0xE2, 0x82]. Invalid bytes in the middle of the buffer ([0xC3, 0x41, 0x42]) are correctly reported as application/octet-stream. The script below shows this.
One thing to consider for #55946: the read tool calls Mime.detect only on the first 256 KiB of a file (FIRST_CHUNK in read-filesystem.ts). That cut can land in the middle of a valid multi-byte character, so { stream: true } may be deliberate there. Always flushing would make some valid UTF-8 files look binary. The fix may need to flush only when the bytes are the whole file, or allow an incomplete character only at the very end of the buffer.
Activity
opencode-agent commentedon Oct 16, 2026
Thanks for the report. I could reproduce this: on v2.0.31 and on the latest
dev(0a03b4b),Mime.detectreturnstext/plainfor[0x61, 0x62, 0xC3]and[0x61, 0xE2, 0x82]. Invalid bytes in the middle of the buffer ([0xC3, 0x41, 0x42]) are correctly reported asapplication/octet-stream. The script below shows this.One thing to consider for #55946: the read tool calls
Mime.detectonly on the first 256 KiB of a file (FIRST_CHUNKinread-filesystem.ts). That cut can land in the middle of a valid multi-byte character, so{ stream: true }may be deliberate there. Always flushing would make some valid UTF-8 files look binary. The fix may need to flush only when the bytes are the whole file, or allow an incomplete character only at the very end of the buffer.Reproduction script (mime-truncated.ts)
Run it:
bun mime-truncated.ts