Skip to content

Conversation

@yuranich
Copy link

What problem does this PR solve?

Fixes #1915 - gguf() fails with ArrayBuffer.prototype.resize: Invalid length parameter when parsing GGUF files using allowLocalFile: true.

Two bugs were identified:

  1. Off-by-one error in chunk fetching: RangeViewLocalFile.fetchChunk() calculates range as [start, end-1] (inclusive end, matching HTTP Range headers), but passes it directly to Blob.slice(start, end) which uses an exclusive end. This causes each chunk to be 1 byte short, creating gaps at chunk boundaries that break metadata parsing.

  2. Negative slice size for small files: FileBlob.slice() could create slices with negative size when the requested range starts beyond EOF. This affects small files and sharded GGUF files where the file is smaller than the 2MB chunk size.

How does it solve it?

  1. Changed fetchChunk() to pass the correct exclusive end to Blob.slice()
  2. Added bounds clamping in FileBlob.slice() to ensure start position never exceeds file end

Breaking changes

None - this is a bugfix that makes local file parsing work correctly.

- Fix off-by-one error in RangeViewLocalFile.fetchChunk: Blob.slice uses
  exclusive end, but range was calculated for inclusive end
- Fix FileBlob.slice to clamp start position to file end, preventing
  negative size when slicing beyond EOF (affects small/sharded files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@huggingface/gguf: ArrayBuffer resize fails on certain GGUF files with local file access

1 participant