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

Fix array length Allocation failed issue when Message is huge #255

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

fanazhe
Copy link

@fanazhe fanazhe commented Feb 3, 2020

When using crypto-js to encrypt and decrypt a file larger than 400MB, the program always crashes and says "FATAL ERROR: invalid array length Allocation failed - JavaScript heap out of memory".
After some research I found crypto-js directly access some array elements which have large index, which caused V8 engine to crash.
This answer https://stackoverflow.com/questions/55465821/55474570 is related.

@fanazhe fanazhe requested a review from evanvosberg February 3, 2020 12:40
@evanvosberg
Copy link
Member

@julkwiec @Alanscut would you be up to review this.

@Alanscut
Copy link
Contributor

@fanazhe would you mind adding a test case? I don't known which algorithom module you used, more information help us verified your PR :)

@fanazhe
Copy link
Author

fanazhe commented Mar 23, 2020

@Alanscut I've pushed more code to fix huge array length issues.

The test code is quite slow running on my computer and I believe it is not suitable to run in browser, so I didn't put it into test folder but only pasted it here.

const path = './build/';

const length = 400 * 1024 * 1024; // 400MB
const message = 'A'.repeat(length);
const privateKey = 'abcdefghijklmnopqrstuvwxyz0123456789';

// Begin large message test
require(path + 'md5')(message); console.log('md5 done');
require(path + 'ripemd160')(message); console.log('ripemd160 done');
require(path + 'sha1')(message); console.log('sha1 done');
require(path + 'sha3')(message); console.log('sha3 done');
require(path + 'sha224')(message); console.log('sha224 done');
require(path + 'sha256')(message); console.log('sha256 done');
require(path + 'sha384')(message); console.log('sha384 done');
require(path + 'sha512')(message); console.log('sha512 done');
require(path + 'hmac-md5')(message, privateKey); console.log('hmac-md5 done');
require(path + 'hmac-ripemd160')(message, privateKey); console.log('hmac-ripemd160 done');
require(path + 'hmac-sha1')(message, privateKey); console.log('hmac-sha1 done');
require(path + 'hmac-sha3')(message, privateKey); console.log('hmac-sha3 done');
require(path + 'hmac-sha224')(message, privateKey); console.log('hmac-sha224 done');
require(path + 'hmac-sha256')(message, privateKey); console.log('hmac-sha256 done');
require(path + 'hmac-sha384')(message, privateKey); console.log('hmac-sha384 done');
require(path + 'hmac-sha512')(message, privateKey); console.log('hmac-sha512 done');
// Done large message test

You can use this code to verify my PR. Thanks!

@peter100u
Copy link

why i not found yours answer

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

Successfully merging this pull request may close these issues.

4 participants