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

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

Closed
ikreymer opened this issue Apr 23, 2023 · 0 comments
Labels
fs Issues and PRs related to the fs subsystem / file system.

Comments

@ikreymer
Copy link

ikreymer commented Apr 23, 2023

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!

@debadree25 debadree25 added the fs Issues and PRs related to the fs subsystem / file system. label Apr 23, 2023
@jasnell jasnell closed this as completed in af9b48a May 5, 2023
targos pushed a commit that referenced this issue May 12, 2023
Signed-off-by: Daeyeon Jeong <daeyeon.dev@gmail.com>
PR-URL: #47691
Fixes: #47683
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants