feross/buffer

Buffer.prototype.slice does not work on iOS 10

jonasschnelli opened this issue · 8 comments

I tracked down an issue on cordova (includes node.js) where Buffer.prototype.slice result in returning the same value as the input buffer.

In iOS <10, this results shifting out 16 bytes:

var out = this.cache.slice(0, 16)
this.cache = this.cache.slice(16)

In iOS 10, this.cache will be unmodified.

I haven't tracked it down, but seems to be a Buffer.TYPED_ARRAY_SUPPORT problem.
If I remove the if at

buffer/index.js

Line 1078 in c5267f4

if (Buffer.TYPED_ARRAY_SUPPORT) {
it does work on iOS 10.

@jonasschnelli Can you share the version of feross/buffer that you're using? npm ls buffer should help 👍

This is due to ES6 support improving in Safari. This issue was fixed a while ago.

It looks like you're not using the latest version of buffer. Please update browserify to v13.x. If you're already on v13.x, then reinstall it to ensure that the latest version of buffer is being used.

Cheers!

Thanks. I'll try to bump to the latest version,

var arr = Uint8Array.from([1, 2, 3, 4])
arr.subarray(0, 2).byteLength

is returning "2" on every other platform, and "1" on ios10

traced it to the function:

Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
? global.TYPED_ARRAY_SUPPORT
: typedArraySupport()
function typedArraySupport () {
try {
var arr = new Uint8Array(1)
arr.foo = function () {
return 42
}
return arr.foo() === 42 && // typed array instances can be augmented
typeof arr.subarray === 'function' && // chrome 9-10 lack subarray
arr.subarray(1, 1).byteLength === 0 // ie10 has broken subarray
} catch (e) {
return false
}
}

@psionic81 That code returns 2 for me.

var arr = Uint8Array.from([1, 2, 3, 4])
alert(arr.subarray(0, 2).byteLength) // 2

yep your suggested fix worked fine, thanks for posting it took so long to track this down to the library that had the dependancy that was the issue.. thanks for making your standards completely unstandard apple lol

I have updated Buffer to 5.0.0, Browserify to 13.1.0, still has that problem.

it craps on Buffer.prototype.slice function

    newBuf = Buffer._augment(this.subarray(start, end))

that subarray return same buffer. it is problem of iOS 10 ?


I fix this by using

    npm ls buffer 

to get all module using 'buffer'. and remove those version older than 4.9.0, or modify the package.json to using latest and reinstall.

Of-course you should 'npm install buffer --save' first

@lamaslam Where did you find that call to Buffer._augment? That was removed in buffer v4. If you see that in your code, then you're using buffer v3 or older somewhere, so it's not surprising that you're still experiencing this bug.

Also, you don't need to explicitly install or depend on this buffer package. Just install browserify v13 and you'll be fine. Double check that you're using the right copy of browserify -- you can install it globally and locally. You might have different versions in each of those locations.