| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Hi! Can you please amend your commit message to follow the guidelines of this repository? It needs to be under 80 characters |
Sorry, something went wrong.
|
Additionally, can you add a test to validate this behavior |
Sorry, something went wrong.
|
I noticed that parallel/test-stream-readable-unpipe-resume is failing on Ubuntu CI, which is strange because it's not failing on my Mac. I'll investigate. |
Sorry, something went wrong.
No need, it's a flaky test. It's a known process deadlock that's being investigated. |
Sorry, something went wrong.
|
@ronag I've requested your review because you were involved in the issue this closes, and you know a lot about buffers that I don't |
Sorry, something went wrong.
|
Don't merge this yet. It's possible to read bytes from outside the source buffer into the target buffer. For example... function _copyActual(source, target, targetStart, sourceStart, sourceEnd) {
if (sourceEnd - sourceStart > target.byteLength - targetStart)
sourceEnd = sourceStart + target.byteLength - targetStart;
let nb = sourceEnd - sourceStart;
const sourceLen = source.byteLength - sourceStart;
if (nb > sourceLen)
nb = sourceLen;
if (nb <= 0)
return 0;
// _copy(source, target, targetStart, sourceStart, nb);
// return nb;
return [source, target, targetStart, sourceStart, nb];
}
let src = Buffer.alloc(50);
let dest = Buffer.alloc(100);
const [_, __, ___, sourceStart, copy_len] = _copyActual(src, dest, 0, -10, 0);
console.log([sourceStart, copy_len]); // [ -10, 10 ]Its probably better here not to trust the caller of _copyActual and to guard the call to _copy with explicit checks. Resolved by: 3c18a13 |
Sorry, something went wrong.
|
@nodejs/buffer PTAL ☝️ |
Sorry, something went wrong.
|
I've updated _copyActual to guard _copy (native binding here) against negative numbers, so there is no risk of potentially allowing out of bounds access in the future. The expected behavior for an out of bounds copy is actually specified by test/parallel/test-buffer-copy.js. At the latest commit 3c18a13, test/parallel/test-buffer-copy.js is passing (along with everything else). |
Sorry, something went wrong.
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #55492 +/- ##
========================================
Coverage 88.41% 88.41%
========================================
Files 653 654 +1
Lines 187435 187575 +140
Branches 36077 36081 +4
========================================
+ Hits 165714 165851 +137
+ Misses 14960 14954 -6
- Partials 6761 6770 +9
... and 33 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Sorry, something went wrong.
|
Not sure what do about code coverage issue. It seems to me that the range check should stay in as preventative measure. |
Sorry, something went wrong.
|
No need to worry about codecov, it's not 100% accurate |
Sorry, something went wrong.
There was a problem hiding this comment.
I think we could just make these asserts. The perf impact is negligable...
Sorry, something went wrong.
There was a problem hiding this comment.
I think we could just make these asserts. The perf impact is negligable...
Sorry, something went wrong.
There was a problem hiding this comment.
Sorry, something went wrong.
|
Turns out the issue also occurs in Buffer.copy. See my comment on the issue thread. |
Sorry, something went wrong.
There was a problem hiding this comment.
What does this mean?
Shouldn't an assert be used instead?
If not, IMO a comment isn't needed at all
Sorry, something went wrong.
There was a problem hiding this comment.
I agree it is redundant. This comment has been removed as of commit 5ca703f.
Sorry, something went wrong.
There was a problem hiding this comment.
| // Test its possible to concat buffers where the total length of the result in bytes | |
| // is greater than 2^32. | |
| // Ref: ... |
Sorry, something went wrong.
Sorry, something went wrong.
There was a problem hiding this comment.
Ditto
Sorry, something went wrong.
Sorry, something went wrong.
|
@redyetidev This is no longer WIP unless you have anymore concerns or suggestions. |
Sorry, something went wrong.
Sorry, something went wrong.
|
I believe CI is failing because the runner is exhausting its memory. We do some pretty large allocations in the unit tests. node/test/parallel/test-buffer-copy.js Lines 239 to 245 in 5ca703f node/test/parallel/test-buffer-concat.js Lines 103 to 113 in 5ca703f Perhaps the tests should be skipped? |
Sorry, something went wrong.
| // - The source slice is not clamped to fit into the target slice. If it won't fit, this throws. | ||
| // - If either the source or target slice are out of bounds, this throws. | ||
| function _copyActual(source, target, targetStart, sourceStart, sourceEnd) { | ||
| assert(isUint8Array(source) && isUint8Array(target)); |
There was a problem hiding this comment.
The assert here is a bit redundant given the checks that are made in the copyImpl call site.
Sorry, something went wrong.
There was a problem hiding this comment.
In my opinion this assert is useful since it makes _copyActual's invariant that source and target need to be Uint8Array explicit.
It indicates to any future/new maintainers needing to call _copyActual what the invariants are. They don't have to guess at the invariants, or deduce the preconditions by exploring all the call-sites of _copyActual.
Sorry, something went wrong.
| new Uint8Array([0x43, 0x44])]), | ||
| Buffer.from('ABCD')); | ||
|
|
||
| // Ref: https://github.com/nodejs/node/issues/55422#issue-2594486812 |
There was a problem hiding this comment.
Nit: please consider expanding the comment a bit here with a short summary of what is being tested for so folks don't have to necessarily follow the link to get the gist.
Sorry, something went wrong.
There was a problem hiding this comment.
I agree that it is better to have the description of the test inlined.
However I was under the impression that the policy was to use refs?
See #55492 (comment) where I actually removed the explanation at the request of another maintainer.
Sorry, something went wrong.
|
What's the status of this? |
Sorry, something went wrong.
| // Enforce: 0 <= sourceStart <= sourceEnd <= source.byteLength | ||
| assert(0 <= sourceStart && sourceStart <= sourceEnd && sourceEnd <= source.byteLength); | ||
| // Enforce: 0 <= targetStart<= target.byteLength | ||
| assert(0 <= targetStart && targetStart <= target.byteLength); |
There was a problem hiding this comment.
This should also likely fix #59985
Sorry, something went wrong.
| const targetCapacity = target.byteLength - targetStart; | ||
| assert(copyLength <= targetCapacity); | ||
|
|
||
| _copy(source, target, targetStart, sourceStart, copyLength); |
There was a problem hiding this comment.
_copy is slower than set but #60399 would fix that
Sorry, something went wrong.
| // - The source slice is not clamped to fit into the target slice. If it won't fit, this throws. | ||
| // - If either the source or target slice are out of bounds, this throws. | ||
| function _copyActual(source, target, targetStart, sourceStart, sourceEnd) { | ||
| assert(isUint8Array(source) && isUint8Array(target)); |
|
@dunpro Please rebase and rectify the concerns |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Closes #55422
This pull request...