aboutsummaryrefslogtreecommitdiff
path: root/js/binary/decoder.js
diff options
context:
space:
mode:
authorPaul Yang <TeBoring@users.noreply.github.com>2017-09-12 15:09:47 -0700
committerGitHub <noreply@github.com>2017-09-12 15:09:47 -0700
commit2bd55a9fbcd2815b3332bf309bc20f59eef0b36b (patch)
tree049577e28c1ee1b2f29fc71c22d06ec6016cae45 /js/binary/decoder.js
parent6a4ffb2f90ef7bbd3f20f2a1db4948630ad37dc8 (diff)
downloadprotobuf-2bd55a9fbcd2815b3332bf309bc20f59eef0b36b.tar.gz
protobuf-2bd55a9fbcd2815b3332bf309bc20f59eef0b36b.tar.bz2
protobuf-2bd55a9fbcd2815b3332bf309bc20f59eef0b36b.zip
Fix js conformance tests. (#3604)
* Fix js conformance tests. * Remove old incorrect compatibility tests
Diffstat (limited to 'js/binary/decoder.js')
-rw-r--r--js/binary/decoder.js27
1 files changed, 12 insertions, 15 deletions
diff --git a/js/binary/decoder.js b/js/binary/decoder.js
index 6db28e7c..a38a5011 100644
--- a/js/binary/decoder.js
+++ b/js/binary/decoder.js
@@ -582,27 +582,24 @@ jspb.BinaryDecoder.prototype.readUnsignedVarint32 = function() {
x |= (temp & 0x0F) << 28;
if (temp < 128) {
// We're reading the high bits of an unsigned varint. The byte we just read
- // also contains bits 33 through 35, which we're going to discard. Those
- // bits _must_ be zero, or the encoding is invalid.
- goog.asserts.assert((temp & 0xF0) == 0);
+ // also contains bits 33 through 35, which we're going to discard.
this.cursor_ += 5;
goog.asserts.assert(this.cursor_ <= this.end_);
return x >>> 0;
}
- // If we get here, we're reading the sign extension of a negative 32-bit int.
- // We can skip these bytes, as we know in advance that they have to be all
- // 1's if the varint is correctly encoded. Since we also know the value is
- // negative, we don't have to coerce it to unsigned before we return it.
-
- goog.asserts.assert((temp & 0xF0) == 0xF0);
- goog.asserts.assert(bytes[this.cursor_ + 5] == 0xFF);
- goog.asserts.assert(bytes[this.cursor_ + 6] == 0xFF);
- goog.asserts.assert(bytes[this.cursor_ + 7] == 0xFF);
- goog.asserts.assert(bytes[this.cursor_ + 8] == 0xFF);
- goog.asserts.assert(bytes[this.cursor_ + 9] == 0x01);
+ // If we get here, we need to truncate coming bytes. However we need to make
+ // sure cursor place is correct.
+ var i = 5;
+ do {
+ goog.asserts.assert(i < 10);
+ if (bytes[this.cursor_ + i] < 128) {
+ break;
+ }
+ i++;
+ } while (1);
- this.cursor_ += 10;
+ this.cursor_ += i + 1;
goog.asserts.assert(this.cursor_ <= this.end_);
return x;
};