REGRESSION (r183373): ASSERT failed in wtf/SHA1.h
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Apr 2015 17:44:53 +0000 (17:44 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Apr 2015 17:44:53 +0000 (17:44 +0000)
commit7b1b1f9c45504dbf0f9d9eca42b9e9a90e39ed10
tree476666bbac16695c7f783c1be2542fe173592b84
parent2d973d60afe9a835de9eb80b71d9ec806e81d02e
REGRESSION (r183373): ASSERT failed in wtf/SHA1.h
https://bugs.webkit.org/show_bug.cgi?id=144257

Reviewed by Darin Adler.

Source/JavaScriptCore:

SHA1 is used to calculate CodeBlockHash.
To calculate hash value, we pass the source code UTF-8 CString to SHA1::addBytes.
However, the source code can contain null character.
So when performing `strlen` on the source code's CString, it returns the incorrect length.
In SHA1::addBytes, there's assertion `input.length() == strlen(string)` and it fails.

In the template-literal-syntax.js, we perform `eval` with the script contains "\0".
As the result, `strlen(string)` accidentally shortened by the contained "\0", and assertion fails.

CString will be changed not to contain a null-character[1]. However, inserting the assertion here
is not correct. Because

1. If CString should not contain a null character, this should be asserted in CString side instead of SHA1::addBytes.
2. If CString can contain a null character, this assertion becomes incorrect.

So this patch just drops the assertion.

In the current implementation, we once convert the entire source code to the newly allocated
UTF-8 string and pass it to the SHA1 processing. However, this is memory consuming.
Ideally, we should stream the decoded bytes into the SHA1 processing iteratively.
We'll implement it in the separate patch[2].

[1]: https://bugs.webkit.org/show_bug.cgi?id=144339
[2]: https://bugs.webkit.org/show_bug.cgi?id=144263

* tests/stress/eval-script-contains-null-character.js: Added.
(shouldBe):
(test):
* tests/stress/template-literal-line-terminators.js:
* tests/stress/template-literal-syntax.js:
* tests/stress/template-literal.js:

Source/WTF:

* wtf/SHA1.h:
(WTF::SHA1::addBytes):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183559 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/tests/stress/eval-script-contains-null-character.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/template-literal-line-terminators.js
Source/JavaScriptCore/tests/stress/template-literal-syntax.js
Source/JavaScriptCore/tests/stress/template-literal.js
Source/WTF/ChangeLog
Source/WTF/wtf/SHA1.h