{"action":"created","issue":{"url":"https://api.github.com/repos/mapbox/pbf/issues/66","repository_url":"https://api.github.com/repos/mapbox/pbf","labels_url":"https://api.github.com/repos/mapbox/pbf/issues/66/labels{/name}","comments_url":"https://api.github.com/repos/mapbox/pbf/issues/66/comments","events_url":"https://api.github.com/repos/mapbox/pbf/issues/66/events","html_url":"https://github.com/mapbox/pbf/issues/66","id":180030241,"number":66,"title":"Issue with packed values with tag > 15","user":{"login":"cschwarz","id":717934,"avatar_url":"https://avatars.githubusercontent.com/u/717934?v=3","gravatar_id":"","url":"https://api.github.com/users/cschwarz","html_url":"https://github.com/cschwarz","followers_url":"https://api.github.com/users/cschwarz/followers","following_url":"https://api.github.com/users/cschwarz/following{/other_user}","gists_url":"https://api.github.com/users/cschwarz/gists{/gist_id}","starred_url":"https://api.github.com/users/cschwarz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cschwarz/subscriptions","organizations_url":"https://api.github.com/users/cschwarz/orgs","repos_url":"https://api.github.com/users/cschwarz/repos","events_url":"https://api.github.com/users/cschwarz/events{/privacy}","received_events_url":"https://api.github.com/users/cschwarz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-29T12:05:14Z","updated_at":"2016-09-29T13:55:17Z","closed_at":null,"body":"After updating to pbf 3.x I have issues reading packed values with a tag number greater than 15.\r\n\r\n```protobuf\r\nsyntax = \"proto3\";\r\npackage ProtobufTest;\r\n\r\nmessage Working {\t\r\n\trepeated uint32 values = 15;\r\n}\r\n\r\nsyntax = \"proto3\";\r\npackage ProtobufTest;\r\n\r\nmessage NotWorking {\t\r\n\trepeated uint32 values = 16;\r\n}\r\n```\r\n\r\nThe problem seems to be in readPackedEnd which guesses the type based on pbf.pos -1.\r\n\r\n```javascript\r\nfunction readPackedEnd(pbf) {\r\n    return (pbf.buf[pbf.pos - 1] & 0x7) === Pbf.Bytes ?\r\n        pbf.readVarint() + pbf.pos : pbf.pos + 1;\r\n}\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/mapbox/pbf/issues/comments/250472735","html_url":"https://github.com/mapbox/pbf/issues/66#issuecomment-250472735","issue_url":"https://api.github.com/repos/mapbox/pbf/issues/66","id":250472735,"user":{"login":"kjvalencik","id":2471970,"avatar_url":"https://avatars.githubusercontent.com/u/2471970?v=3","gravatar_id":"","url":"https://api.github.com/users/kjvalencik","html_url":"https://github.com/kjvalencik","followers_url":"https://api.github.com/users/kjvalencik/followers","following_url":"https://api.github.com/users/kjvalencik/following{/other_user}","gists_url":"https://api.github.com/users/kjvalencik/gists{/gist_id}","starred_url":"https://api.github.com/users/kjvalencik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kjvalencik/subscriptions","organizations_url":"https://api.github.com/users/kjvalencik/orgs","repos_url":"https://api.github.com/users/kjvalencik/repos","events_url":"https://api.github.com/users/kjvalencik/events{/privacy}","received_events_url":"https://api.github.com/users/kjvalencik/received_events","type":"User","site_admin":false},"created_at":"2016-09-29T13:55:17Z","updated_at":"2016-09-29T13:55:17Z","body":"@mourner This is the only fix I can come up with that doesn't change the API to pass `type` around. Thoughts?\r\n\r\n```diff\r\ndiff --git a/index.js b/index.js\r\nindex 17d2f0f..a60985e 100644\r\n--- a/index.js\r\n+++ b/index.js\r\n@@ -7,6 +7,7 @@ var ieee754 = require('ieee754');\r\n function Pbf(buf) {\r\n     this.buf = ArrayBuffer.isView(buf) ? buf : new Uint8Array(buf || 0);\r\n     this.pos = 0;\r\n+    this.type = 0;\r\n     this.length = this.buf.length;\r\n }\r\n \r\n@@ -34,6 +35,7 @@ Pbf.prototype = {\r\n                 tag = val >> 3,\r\n                 startPos = this.pos;\r\n \r\n+            this.type = val & 0x7;\r\n             readField(tag, result, this);\r\n \r\n             if (this.pos === startPos) this.skip(val);\r\n@@ -393,7 +395,7 @@ function readVarintRemainder(l, s, p) {\r\n }\r\n \r\n function readPackedEnd(pbf) {\r\n-    return (pbf.buf[pbf.pos - 1] & 0x7) === Pbf.Bytes ?\r\n+    return pbf.type === Pbf.Bytes ?\r\n         pbf.readVarint() + pbf.pos : pbf.pos + 1;\r\n }\r\n```"}}
{"actor":{"display_login":"kjvalencik"}}