Last Comment Bug 653175 - Incorrect result with \0 in property name
: Incorrect result with \0 in property name
Status: RESOLVED FIXED
[inbound]
:
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: unspecified
: All All
: -- normal (vote)
: mozilla8
Assigned To: Tom Schuster [:evilpie]
:
Mentors:
Depends on:
Blocks: es5
  Show dependency treegraph
 
Reported: 2011-04-27 10:28 PDT by Jan de Mooij [:jandem] (PTO until July 31)
Modified: 2011-08-06 03:01 PDT (History)
11 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
v1 (3.12 KB, patch)
2011-07-28 09:15 PDT, Tom Schuster [:evilpie]
no flags Details | Diff | Splinter Review
v2 (7.99 KB, patch)
2011-08-02 13:44 PDT, Tom Schuster [:evilpie]
no flags Details | Diff | Splinter Review
v3 (8.63 KB, patch)
2011-08-04 13:16 PDT, Tom Schuster [:evilpie]
no flags Details | Diff | Splinter Review
v3 with test (9.96 KB, patch)
2011-08-04 13:53 PDT, Tom Schuster [:evilpie]
jorendorff: review+
Details | Diff | Splinter Review

Description Jan de Mooij [:jandem] (PTO until July 31) 2011-04-27 10:28:22 PDT
js> [1, 2]["1" + "\0"] 
2
js> [1, 2]["1" + "\0aaaaa"] 
2

I don't know the exact ES5 section but I think this should print |undefined|. Opera, Chrome and Safari also return undefined.
Comment 1 Tom Schuster [:evilpie] 2011-06-13 12:20:59 PDT
The problem is js_StringIsIndex assuming "\0" is the end of a string.
Comment 2 Tom Schuster [:evilpie] 2011-07-28 09:15:33 PDT
Created attachment 549133 [details] [diff] [review]
v1
Comment 3 Tom Schuster [:evilpie] 2011-07-28 09:16:39 PDT
I changed, (previous == (MAXINDEX / 10) && c <= (MAXINDEX % 10)), otherwise we wouldn't allow the highest possible value.
Comment 4 Jason Orendorff [:jorendorff] 2011-07-28 10:12:20 PDT
Comment on attachment 549133 [details] [diff] [review]
v1

Based on the comment there, I think eliminating 2^32-1 is intentional. But then MAXINDEX is a misleading name.

Otherwise, looks good.

Clearing review.
Comment 5 Tom Schuster [:evilpie] 2011-08-02 13:44:48 PDT
Created attachment 550188 [details] [diff] [review]
v2

The asserts in InitArrayElements scared me a bit :/, so i rather left them untouched.
Comment 6 Jason Orendorff [:jorendorff] 2011-08-04 12:53:18 PDT
Comment on attachment 550188 [details] [diff] [review]
v2

Review of attachment 550188 [details] [diff] [review]:
-----------------------------------------------------------------

Clearing the review flag again; Tom's going to post a new patch.

::: js/src/jsarray.cpp
@@ +124,2 @@
>  
>  static inline bool

Nit: House style is to avoid multiple blank lines together, so please delete two of these.

@@ -151,5 @@
> - * an atomized string.
> - */
> -bool
> -js_StringIsIndex(JSLinearString *str, jsuint *indexp)
> -{

Sorry, I know you asked about moving this on IRC and I thought it was a good idea, but now I think it's better to leave it where it is.

@@ +1322,5 @@
>  
>  static JSBool
>  InitArrayElements(JSContext *cx, JSObject *obj, jsuint start, jsuint count, Value *vector)
>  {
> +    const uint32 MAXINDEX = 4294967294u;

Heh! No, put MAX_ARRAY_INDEX in one place, perhaps jsarray.h; don't define it with the same value, and different names, in multiple places. :)

@@ +1327,1 @@
>      JS_ASSERT(count < MAXINDEX);

Since you changed MAXINDEX from 4294967295u to 4294967294u, the assertion has to change from < to <=. Likewise for any other places where MAXINDEX is used.

::: js/src/jsnum.cpp
@@ +1324,5 @@
> + *
> + */
> +bool
> +StringIsIndex(JSLinearString *str, jsuint *indexp)
> +{

On IRC just now we settled on naming this js::StringIsArrayIndex.
Comment 7 Tom Schuster [:evilpie] 2011-08-04 13:16:23 PDT
Created attachment 550810 [details] [diff] [review]
v3
Comment 8 Tom Schuster [:evilpie] 2011-08-04 13:53:04 PDT
Created attachment 550823 [details] [diff] [review]
v3 with test

So added test for this specific bug [0, 1, 2]['1\0'] would return 1. I also was curious whether or test suite catches wrong behavior around Array Indexes (to high or low max index) and luckily it does :)
Comment 9 Jason Orendorff [:jorendorff] 2011-08-05 04:39:44 PDT
Comment on attachment 550823 [details] [diff] [review]
v3 with test

Review of attachment 550823 [details] [diff] [review]:
-----------------------------------------------------------------

Please run benchmarks to make sure this doesn't slow anything down. It shouldn't, because this code shouldn't be hot anymore.

r=me with the minor fixes below.

::: js/src/jsarray.cpp
@@ +179,1 @@
>   */

Heh. Thanks for fixing this comment. While you're in here, please fix the JSVAL_IS_INT part too: we would also have to check JSVAL_IS_DOUBLE. And anyway it seems like that part of the comment fits better on js_CheckForStringIndex than here; move it if you want to.

Micro-nit: Delete the line here that just contains a "*".

@@ +184,5 @@
> +    uint32 length = str->length();
> +    const jschar *end = s + length;
> +
> +    if (length == 0 || length > sizeof("4294967294") || !JS7_ISDEC(*s))
> +        return false;

sizeof("4294967294") is 11, due to the '\0', but you want to return false if the string is longer than 10 characters.

::: js/src/tests/ecma_5/Array/index-with-null-character.js
@@ +4,5 @@
> + */
> +
> +var BUGNUMBER = 653175;
> +var summary = 'Incorrect result with \0 in property name';
> +print(BUGNUMBER + ': ' + summary);

These three lines are worthless. I would delete them, but it's totally up to you. Some JS hackers still include them.
Comment 11 Marco Bonardo [::mak] 2011-08-06 03:01:37 PDT
http://hg.mozilla.org/mozilla-central/rev/66ccc3cf04bc

Note You need to log in before you can comment on or make changes to this bug.