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

Buffer.prototype.slice does not work on iOS 10 #136

Closed
jonasschnelli opened this issue Sep 16, 2016 · 8 comments
Closed

Buffer.prototype.slice does not work on iOS 10 #136

jonasschnelli opened this issue Sep 16, 2016 · 8 comments

Comments

@jonasschnelli
Copy link

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.

@feross
Copy link
Owner

feross commented Sep 16, 2016

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

@feross
Copy link
Owner

feross commented Sep 16, 2016

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!

@feross feross closed this as completed Sep 16, 2016
@jonasschnelli
Copy link
Author

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

@psionic81
Copy link

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
}
}

@feross
Copy link
Owner

feross commented Sep 19, 2016

@psionic81 That code returns 2 for me.

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

@psionic81
Copy link

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

@lamaslam
Copy link

lamaslam commented Sep 29, 2016

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

@feross
Copy link
Owner

feross commented Sep 29, 2016

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants