Skip to content

Commit caf005e

Browse files
backesCommit Bot
authored andcommitted
Hash all strings as unsigned values
A previous CL (https://crrev.com/c/1926769) changed hashing to always treat the input as signed values. This causes problems, since the hash of a one-byte string differs the hash of the identical two-byte string. Hence this CL switches to treating all values as unsigned in hashing. The bug cannot easily be reproduced in v8 alone, since we would need to create an internalized two-byte string, which contains one-byte data. Blink manages to create such a string via external strings. R=jkummerow@chromium.org Bug: chromium:1025184, chromium:1027131 Change-Id: Id41aa0e463691c02099a08c6e9d837a079c872df Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1930615 Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Commit-Queue: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/master@{#65113}
1 parent 8764dbc commit caf005e

2 files changed

Lines changed: 30 additions & 30 deletions

File tree

src/strings/string-hasher-inl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ uint32_t StringHasher::HashSequentialString(const char_t* chars_raw, int length,
5454
uint64_t seed) {
5555
STATIC_ASSERT(std::is_integral<char_t>::value);
5656
STATIC_ASSERT(sizeof(char_t) <= 2);
57-
using schar = typename std::make_signed<char_t>::type;
58-
const schar* chars = reinterpret_cast<const schar*>(chars_raw);
57+
using uchar = typename std::make_unsigned<char_t>::type;
58+
const uchar* chars = reinterpret_cast<const uchar*>(chars_raw);
5959
DCHECK_LE(0, length);
6060
DCHECK_IMPLIES(0 < length, chars != nullptr);
6161
if (length >= 1) {
@@ -86,7 +86,7 @@ uint32_t StringHasher::HashSequentialString(const char_t* chars_raw, int length,
8686
uint32_t is_integer_index = 0;
8787
uint32_t running_hash = static_cast<uint32_t>(seed);
8888
uint64_t index_big = index;
89-
const schar* end = &chars[length];
89+
const uchar* end = &chars[length];
9090
while (chars != end) {
9191
if (is_integer_index == 0 && !TryAddIndexChar(&index_big, *chars)) {
9292
is_integer_index = String::kIsNotIntegerIndexMask;
@@ -107,7 +107,7 @@ uint32_t StringHasher::HashSequentialString(const char_t* chars_raw, int length,
107107

108108
// Non-index hash.
109109
uint32_t running_hash = static_cast<uint32_t>(seed);
110-
const schar* end = &chars[length];
110+
const uchar* end = &chars[length];
111111
while (chars != end) {
112112
running_hash = AddCharacterCore(running_hash, *chars++);
113113
}

test/inspector/debugger/wasm-stepping-byte-offsets-expected.txt

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
Tests stepping through wasm scripts by byte offsets
22
Setting up global instance variable.
3-
Got wasm script: wasm://wasm/41f464ee
4-
Requesting source for wasm://wasm/41f464ee...
3+
Got wasm script: wasm://wasm/7dfc8356
4+
Requesting source for wasm://wasm/7dfc8356...
55
Source retrieved without error: true
6-
Setting breakpoint on offset 59 (should be propagated to 60, the offset of the call), url wasm://wasm/41f464ee
6+
Setting breakpoint on offset 59 (should be propagated to 60, the offset of the call), url wasm://wasm/7dfc8356
77
{
88
columnNumber : 60
99
lineNumber : 0
1010
scriptId : <scriptId>
1111
}
12-
Paused at wasm://wasm/41f464ee/41f464ee-1:9:6
12+
Paused at wasm://wasm/7dfc8356/7dfc8356-1:9:6
1313
at wasm_B (9:6):
1414
- scope (global):
1515
-- skipped
@@ -20,7 +20,7 @@ at (anonymous) (0:17):
2020
- scope (global):
2121
-- skipped
2222
Debugger.stepInto called
23-
Paused at wasm://wasm/41f464ee/41f464ee-0:1:2
23+
Paused at wasm://wasm/7dfc8356/7dfc8356-0:1:2
2424
at wasm_A (1:2):
2525
- scope (global):
2626
-- skipped
@@ -37,7 +37,7 @@ at (anonymous) (0:17):
3737
- scope (global):
3838
-- skipped
3939
Debugger.stepOver called
40-
Paused at wasm://wasm/41f464ee/41f464ee-0:2:2
40+
Paused at wasm://wasm/7dfc8356/7dfc8356-0:2:2
4141
at wasm_A (2:2):
4242
- scope (global):
4343
-- skipped
@@ -54,7 +54,7 @@ at (anonymous) (0:17):
5454
- scope (global):
5555
-- skipped
5656
Debugger.stepOut called
57-
Paused at wasm://wasm/41f464ee/41f464ee-1:10:6
57+
Paused at wasm://wasm/7dfc8356/7dfc8356-1:10:6
5858
at wasm_B (10:6):
5959
- scope (global):
6060
-- skipped
@@ -65,7 +65,7 @@ at (anonymous) (0:17):
6565
- scope (global):
6666
-- skipped
6767
Debugger.stepOut called
68-
Paused at wasm://wasm/41f464ee/41f464ee-1:9:6
68+
Paused at wasm://wasm/7dfc8356/7dfc8356-1:9:6
6969
at wasm_B (9:6):
7070
- scope (global):
7171
-- skipped
@@ -76,7 +76,7 @@ at (anonymous) (0:17):
7676
- scope (global):
7777
-- skipped
7878
Debugger.stepOver called
79-
Paused at wasm://wasm/41f464ee/41f464ee-1:10:6
79+
Paused at wasm://wasm/7dfc8356/7dfc8356-1:10:6
8080
at wasm_B (10:6):
8181
- scope (global):
8282
-- skipped
@@ -87,7 +87,7 @@ at (anonymous) (0:17):
8787
- scope (global):
8888
-- skipped
8989
Debugger.stepInto called
90-
Paused at wasm://wasm/41f464ee/41f464ee-1:1:2
90+
Paused at wasm://wasm/7dfc8356/7dfc8356-1:1:2
9191
at wasm_B (1:2):
9292
- scope (global):
9393
-- skipped
@@ -98,7 +98,7 @@ at (anonymous) (0:17):
9898
- scope (global):
9999
-- skipped
100100
Debugger.resume called
101-
Paused at wasm://wasm/41f464ee/41f464ee-1:9:6
101+
Paused at wasm://wasm/7dfc8356/7dfc8356-1:9:6
102102
at wasm_B (9:6):
103103
- scope (global):
104104
-- skipped
@@ -109,7 +109,7 @@ at (anonymous) (0:17):
109109
- scope (global):
110110
-- skipped
111111
Debugger.stepInto called
112-
Paused at wasm://wasm/41f464ee/41f464ee-0:1:2
112+
Paused at wasm://wasm/7dfc8356/7dfc8356-0:1:2
113113
at wasm_A (1:2):
114114
- scope (global):
115115
-- skipped
@@ -126,7 +126,7 @@ at (anonymous) (0:17):
126126
- scope (global):
127127
-- skipped
128128
Debugger.stepOut called
129-
Paused at wasm://wasm/41f464ee/41f464ee-1:10:6
129+
Paused at wasm://wasm/7dfc8356/7dfc8356-1:10:6
130130
at wasm_B (10:6):
131131
- scope (global):
132132
-- skipped
@@ -137,7 +137,7 @@ at (anonymous) (0:17):
137137
- scope (global):
138138
-- skipped
139139
Debugger.stepInto called
140-
Paused at wasm://wasm/41f464ee/41f464ee-1:1:2
140+
Paused at wasm://wasm/7dfc8356/7dfc8356-1:1:2
141141
at wasm_B (1:2):
142142
- scope (global):
143143
-- skipped
@@ -148,7 +148,7 @@ at (anonymous) (0:17):
148148
- scope (global):
149149
-- skipped
150150
Debugger.stepInto called
151-
Paused at wasm://wasm/41f464ee/41f464ee-1:2:4
151+
Paused at wasm://wasm/7dfc8356/7dfc8356-1:2:4
152152
at wasm_B (2:4):
153153
- scope (global):
154154
-- skipped
@@ -159,7 +159,7 @@ at (anonymous) (0:17):
159159
- scope (global):
160160
-- skipped
161161
Debugger.stepInto called
162-
Paused at wasm://wasm/41f464ee/41f464ee-1:3:4
162+
Paused at wasm://wasm/7dfc8356/7dfc8356-1:3:4
163163
at wasm_B (3:4):
164164
- scope (global):
165165
-- skipped
@@ -170,7 +170,7 @@ at (anonymous) (0:17):
170170
- scope (global):
171171
-- skipped
172172
Debugger.stepInto called
173-
Paused at wasm://wasm/41f464ee/41f464ee-1:4:6
173+
Paused at wasm://wasm/7dfc8356/7dfc8356-1:4:6
174174
at wasm_B (4:6):
175175
- scope (global):
176176
-- skipped
@@ -181,7 +181,7 @@ at (anonymous) (0:17):
181181
- scope (global):
182182
-- skipped
183183
Debugger.stepInto called
184-
Paused at wasm://wasm/41f464ee/41f464ee-1:5:6
184+
Paused at wasm://wasm/7dfc8356/7dfc8356-1:5:6
185185
at wasm_B (5:6):
186186
- scope (global):
187187
-- skipped
@@ -192,7 +192,7 @@ at (anonymous) (0:17):
192192
- scope (global):
193193
-- skipped
194194
Debugger.stepInto called
195-
Paused at wasm://wasm/41f464ee/41f464ee-1:6:6
195+
Paused at wasm://wasm/7dfc8356/7dfc8356-1:6:6
196196
at wasm_B (6:6):
197197
- scope (global):
198198
-- skipped
@@ -203,7 +203,7 @@ at (anonymous) (0:17):
203203
- scope (global):
204204
-- skipped
205205
Debugger.stepInto called
206-
Paused at wasm://wasm/41f464ee/41f464ee-1:7:6
206+
Paused at wasm://wasm/7dfc8356/7dfc8356-1:7:6
207207
at wasm_B (7:6):
208208
- scope (global):
209209
-- skipped
@@ -214,7 +214,7 @@ at (anonymous) (0:17):
214214
- scope (global):
215215
-- skipped
216216
Debugger.stepInto called
217-
Paused at wasm://wasm/41f464ee/41f464ee-1:8:6
217+
Paused at wasm://wasm/7dfc8356/7dfc8356-1:8:6
218218
at wasm_B (8:6):
219219
- scope (global):
220220
-- skipped
@@ -225,7 +225,7 @@ at (anonymous) (0:17):
225225
- scope (global):
226226
-- skipped
227227
Debugger.stepInto called
228-
Paused at wasm://wasm/41f464ee/41f464ee-1:9:6
228+
Paused at wasm://wasm/7dfc8356/7dfc8356-1:9:6
229229
at wasm_B (9:6):
230230
- scope (global):
231231
-- skipped
@@ -236,7 +236,7 @@ at (anonymous) (0:17):
236236
- scope (global):
237237
-- skipped
238238
Debugger.stepInto called
239-
Paused at wasm://wasm/41f464ee/41f464ee-0:1:2
239+
Paused at wasm://wasm/7dfc8356/7dfc8356-0:1:2
240240
at wasm_A (1:2):
241241
- scope (global):
242242
-- skipped
@@ -253,7 +253,7 @@ at (anonymous) (0:17):
253253
- scope (global):
254254
-- skipped
255255
Debugger.stepInto called
256-
Paused at wasm://wasm/41f464ee/41f464ee-0:2:2
256+
Paused at wasm://wasm/7dfc8356/7dfc8356-0:2:2
257257
at wasm_A (2:2):
258258
- scope (global):
259259
-- skipped
@@ -270,7 +270,7 @@ at (anonymous) (0:17):
270270
- scope (global):
271271
-- skipped
272272
Debugger.stepInto called
273-
Paused at wasm://wasm/41f464ee/41f464ee-0:3:0
273+
Paused at wasm://wasm/7dfc8356/7dfc8356-0:3:0
274274
at wasm_A (3:0):
275275
- scope (global):
276276
-- skipped
@@ -287,7 +287,7 @@ at (anonymous) (0:17):
287287
- scope (global):
288288
-- skipped
289289
Debugger.stepInto called
290-
Paused at wasm://wasm/41f464ee/41f464ee-1:10:6
290+
Paused at wasm://wasm/7dfc8356/7dfc8356-1:10:6
291291
at wasm_B (10:6):
292292
- scope (global):
293293
-- skipped

0 commit comments

Comments
 (0)