Commit d550e678 authored by Calder Kitagawa's avatar Calder Kitagawa Committed by Commit Bot

[Zucchini] Fix undefined shift in GetSleb128.

A left shift resulting in truncation is undefined behavior on signed
int types in C++. It is fine to left shift an unsigned type because
there is no issues with two's complement representation or sign bits.
To get around this we need to perform the shift on the uint type and
recast it to a signed int type.

Bug: 860067
Change-Id: Ibace5aceb17c4435d6d37d5e37a16fa781c7dd99
Reviewed-on: https://chromium-review.googlesource.com/1126169Reviewed-by: default avatarSamuel Huang <huangs@chromium.org>
Commit-Queue: Calder Kitagawa <ckitagawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572577}
parent c2ffe932
......@@ -80,7 +80,7 @@ bool BufferSource::GetSleb128(int32_t* ret) {
for (int shift = 0; shift < shift_lim; shift += 7, ++cur) {
uint32_t b = *cur;
// When |shift == 28|, |(b & 0x7F) << shift| discards the "???" bits.
value |= static_cast<int32_t>(b & 0x7F) << shift;
value |= static_cast<int32_t>(static_cast<uint32_t>(b & 0x7F) << shift);
if (!(b & 0x80)) {
*ret = (shift == 28) ? value : SignExtend(shift + 6, value);
seek(cur + 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment