-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with packed values with tag > 15 #66
Comments
Confirmed this issue and the location. While clearly not a proper fix, adding the following resolves the issue. Breaking PR: https://github.com/mapbox/pbf/pull/57/files diff --git a/index.js b/index.js
index 17d2f0f..f532853 100644
--- a/index.js
+++ b/index.js
@@ -34,6 +34,7 @@ Pbf.prototype = {
tag = val >> 3,
startPos = this.pos;
+ global.__val = val;
readField(tag, result, this);
if (this.pos === startPos) this.skip(val);
@@ -393,7 +394,7 @@ function readVarintRemainder(l, s, p) {
}
function readPackedEnd(pbf) {
- return (pbf.buf[pbf.pos - 1] & 0x7) === Pbf.Bytes ?
+ return (global.__val & 0x7) === Pbf.Bytes ?
pbf.readVarint() + pbf.pos : pbf.pos + 1;
} Previously, I had a PR that passed the type through but, this was a breaking change to the interface. I'll take another look to see if there is a better way to get the EDITThis bug doesn't strictly effect all ids over |
@mourner This is the only fix I can come up with that doesn't change the API to pass diff --git a/index.js b/index.js
index 17d2f0f..a60985e 100644
--- a/index.js
+++ b/index.js
@@ -7,6 +7,7 @@ var ieee754 = require('ieee754');
function Pbf(buf) {
this.buf = ArrayBuffer.isView(buf) ? buf : new Uint8Array(buf || 0);
this.pos = 0;
+ this.type = 0;
this.length = this.buf.length;
}
@@ -34,6 +35,7 @@ Pbf.prototype = {
tag = val >> 3,
startPos = this.pos;
+ this.type = val & 0x7;
readField(tag, result, this);
if (this.pos === startPos) this.skip(val);
@@ -393,7 +395,7 @@ function readVarintRemainder(l, s, p) {
}
function readPackedEnd(pbf) {
- return (pbf.buf[pbf.pos - 1] & 0x7) === Pbf.Bytes ?
+ return pbf.type === Pbf.Bytes ?
pbf.readVarint() + pbf.pos : pbf.pos + 1;
} |
I think that's even better than the previous implementation. I'll do a patch release tomorrow. @kjvalencik thanks for reacting so quickly! |
Released as 3.0.2. |
Thanks for the fast bug fix and release! |
After updating to pbf 3.x I have issues reading packed values with a tag number greater than 15.
The problem seems to be in readPackedEnd which guesses the type based on pbf.pos -1.
The text was updated successfully, but these errors were encountered: