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

new Blob([new Uint16Array([1])]) has size 1 instead of 2 #40705

Closed
Gozala opened this issue Nov 2, 2021 · 1 comment · Fixed by #40706
Closed

new Blob([new Uint16Array([1])]) has size 1 instead of 2 #40705

Gozala opened this issue Nov 2, 2021 · 1 comment · Fixed by #40706
Labels
buffer Issues and PRs related to the buffer subsystem.

Comments

@Gozala
Copy link
Contributor

Gozala commented Nov 2, 2021

Version

v16.13.0

Platform

Darwin vashli.local 20.6.0 Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64 x86_64

Subsystem

No response

What steps will reproduce the bug?

If you run following with node 16.3

node -e 'assert.equal(new (require("buffer").Blob)([new Uint16Array([1])]).size, 2)'

Produces output

node:assert:123
  throw new AssertionError(obj);

AssertionError [ERR_ASSERTION]: 1 == 2
    at [eval]:1:8
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:305:38)
    at node:internal/process/execution:81:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:80:60)
    at node:internal/main/eval_string:27:3 {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: 1,
  expected: 2,
  operator: '=='
}

Which mismatches expected Blob behavior

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior?

assert should pass and generally blob behavior should match one from web

What do you see instead?

No response

Additional information

Issue with the following line

node/lib/internal/blob.js

Lines 109 to 128 in dd52c05

function getSource(source, endings) {
if (isBlob(source))
return [source.size, source[kHandle]];
if (isAnyArrayBuffer(source)) {
source = new Uint8Array(source);
} else if (!isArrayBufferView(source)) {
source = `${source}`;
if (endings === 'native')
source = RegExpPrototypeSymbolReplace(/\n|\r\n/g, source, lazyEOL());
source = enc.encode(source);
}
// We copy into a new Uint8Array because the underlying
// BackingStores are going to be detached and owned by
// the Blob. We also don't want to have to worry about
// byte offsets.
source = new Uint8Array(source);
return [source.byteLength, source];
}

Which should return following instead

  source = new Uint8Array(source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength));
  return [source.byteLength, source];
@benjamingr
Copy link
Member

@jasnell

@Mesteery Mesteery added the buffer Issues and PRs related to the buffer subsystem. label Nov 3, 2021
aduh95 pushed a commit that referenced this issue Dec 10, 2021
Fixes: #40705
    
PR-URL: #40706
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
danielleadams pushed a commit that referenced this issue Dec 13, 2021
Fixes: #40705
    
PR-URL: #40706
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
danielleadams pushed a commit that referenced this issue Dec 14, 2021
Fixes: #40705
    
PR-URL: #40706
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
danielleadams pushed a commit that referenced this issue Jan 31, 2022
Fixes: #40705
    
PR-URL: #40706
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
danielleadams pushed a commit that referenced this issue Jan 31, 2022
Fixes: #40705
    
PR-URL: #40706
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Linkgoron pushed a commit to Linkgoron/node that referenced this issue Jan 31, 2022
Fixes: nodejs#40705
    
PR-URL: nodejs#40706
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
danielleadams pushed a commit that referenced this issue Feb 1, 2022
Fixes: #40705
    
PR-URL: #40706
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
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
buffer Issues and PRs related to the buffer subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants