Skip to content
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

Chromium consistently crash after processing ~990 files (of several specific types) with fileTypeFromBlob - a.readFromStream WebStreamReader.js - TypeError: network error #678

Closed
3 tasks done
josephrocca opened this issue Oct 12, 2024 · 2 comments · Fixed by Borewit/peek-readable#765, Borewit/strtok3#1172 or #680
Labels

Comments

@josephrocca
Copy link

josephrocca commented Oct 12, 2024

Description

This may be a Chrome bug because it works in Firefox. It crashes at around 990 iterations when the selected file is jpg/png/webp/mkv/gz/safetensors and possibly many other types, and for some reason it does not crash on some other file types I tested (like zip archives). You can open about:blank in your browser, then open DevTools and paste this, and select any random image from your computer:

let fileType = await import("https://cdn.jsdelivr.net/npm/file-type@19.5.0/+esm");
let fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.onchange = async e => {
  let file = e.target.files[0];
  for(let i = 0; i < 10000; i++) {
    // let t = await fileType.fileTypeFromBuffer(await file.arrayBuffer()); // ✅ This works fine
    let t = await fileType.fileTypeFromBlob(file); // ❌ This crashes after about 990 iterations
    console.log(i, t);
  }
};
fileInput.click();

Here's the error:

WebStreamReader.js:17 Uncaught (in promise) TypeError: network error
    at a.readFromStream (WebStreamReader.js:17:42)
    at a.readRemainderFromStream (AbstractStreamReader.js:70:41)
    at a.read (AbstractStreamReader.js:32:33)
    at a.peek (AbstractStreamReader.js:23:38)
    at s.peekBuffer (ReadStreamTokenizer.js:63:53)
    at x.parse (core.js:174:19)
    at x.fromTokenizer (core.js:81:15)
    at x.fromStream (core.js:105:22)

Notes:

  • I've tested in Chrome v129 and v130 on Ubuntu 22.04.
  • As noted above, it works fine in Firefox.
  • As noted above, it works fine if I use fileTypeFromBuffer.
  • It doesn't matter whether I'm processing the same blob multiple times, or processing a different blob at each iteration.
  • After it crashes, if you try again, it will immediately crash on the first iteration. You need to refresh the page to fix it.
  • It doesn't seem to be related to the size of the file. E.g. 50mb file and 12kb file both crash after ~990 iterations.
  • For me this is easy to work around (just use fileTypeFromBuffer), so this issue is just to document the bug, be it a Chromium one or a file-type one.

Example file:

It happens for any jpg/png/webp as far as I can tell, but just in case, here's an example I tested/replicated the issue on:

Existing Issue Check

  • I have searched the existing issues and could not find any related to my problem.

ESM (ECMAScript Module) Requirement Acknowledgment

  • My project is an ESM project and my package.json contains the following entry: "type": "module".

File-Type Scope Acknowledgment

  • I understand that file-type detects binary file types and not text or other formats.
@Borewit
Copy link
Collaborator

Borewit commented Oct 13, 2024

I tested the above code, on Windows 11, with Chrome 129, loading some JPEG files, and it completed without crashing.

@Borewit
Copy link
Collaborator

Borewit commented Oct 13, 2024

On Fedora Linux 40, with Chrome 129, I could reproduce the issue.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants