Closed
Bug 1280052
Opened 9 years ago
Closed 9 years ago
Buffer.slice is broken in FF 49.0a2 (2016-06-13)
Categories
(Firefox :: Untriaged, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: james, Unassigned)
Details
(Whiteboard: [specification][type:bug])
What did you do?
================
We are using babel and it is including what appears to be Mozilla code. I'm really not 100% sure, I appreciate your having a look.
This bug is really quite obvious when you see it.
1. I used webpack to include code that references the Buffer object.
2. In the console I run: new Buffer("abc").slice(0, 2).toString()
What happened?
==============
"abc" was returned
What should have happened?
==========================
"ab"
Is there anything else we should know?
======================================
I stepped into the code and found the error happens somewhere after this.subarray(start, end) is called. It does not matter how large the buffer it, it will return the entire buffer when calling slice(0, buf.length - n).
```
Buffer.prototype.slice = function slice (start, end) {
var len = this.length
start = ~~start
end = end === undefined ? len : ~~end
if (start < 0) {
start += len
if (start < 0) start = 0
} else if (start > len) {
start = len
}
if (end < 0) {
end += len
if (end < 0) end = 0
} else if (end > len) {
end = len
}
if (end < start) end = start
var newBuf
if (Buffer.TYPED_ARRAY_SUPPORT) {
newBuf = Buffer._augment(this.subarray(start, end))
} else {
var sliceLen = end - start
newBuf = new Buffer(sliceLen, undefined)
for (var i = 0; i < sliceLen; i++) {
newBuf[i] = this[i + start]
}
}
if (newBuf.length) newBuf.parent = this.parent || this
return newBuf
}
```
Updated•9 years ago
|
Component: BrowserCompat → Untriaged
Product: Mozilla Developer Network → Firefox
Comment 1•9 years ago
|
||
Seems this was a `buffer` issue and not a Firefox issue; for the backstory see:
- https://github.com/feross/buffer/pull/97
- https://github.com/feross/buffer/issues/120
Comment 2•9 years ago
|
||
Based on Nolan comment, I will close this as Resolved: Invalid. Feel free to reopen it if you have a different opinion.
Status: UNCONFIRMED → RESOLVED
Closed: 9 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•