Skip to content

slice on blob created with fs.openAsBlob results in incorrect length (end + start instead of end - start?) #47683

Closed
@ikreymer

Description

@ikreymer

When performing a slice() on a blob created with fs.openAsBlob, the offset is correct but the length is not.

Fairly easy to repro with any file (on 19.8.1)

  const blob = await openAsBlob("test.txt");
  const res = blob.slice(10, 20);
  console.log(res.size);
  const data = await res.arrayBuffer();
  console.log(data.byteLength);

Running this with any files results in:

10
30

With slice [10, 20) the blob should be of length 10 and blob.size returns 10.
But the actual data read is 30 bytes.

My guess what that perhaps there's a length = end + start instead of length = end - start somewhere,
and I think that is what seems to be happening here:

new_end = std::min(end.value() + start, new_end);

Seems like this should just be:

new_end = std::min(end.value() + start_, new_end); 

adding the original start_ not the new start

Edit: took me a couple of tries to get it right - the end instead of length somehow makes it more tricky!

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to the fs subsystem / file system.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions