{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/9101","repository_url":"https://api.github.com/repos/nodejs/node","labels_url":"https://api.github.com/repos/nodejs/node/issues/9101/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/9101/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/9101/events","html_url":"https://github.com/nodejs/node/pull/9101","id":183132801,"number":9101,"title":"buffer: coerce slice parameters consistenly","user":{"login":"thefourtheye","id":696611,"avatar_url":"https://avatars.githubusercontent.com/u/696611?v=3","gravatar_id":"","url":"https://api.github.com/users/thefourtheye","html_url":"https://github.com/thefourtheye","followers_url":"https://api.github.com/users/thefourtheye/followers","following_url":"https://api.github.com/users/thefourtheye/following{/other_user}","gists_url":"https://api.github.com/users/thefourtheye/gists{/gist_id}","starred_url":"https://api.github.com/users/thefourtheye/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thefourtheye/subscriptions","organizations_url":"https://api.github.com/users/thefourtheye/orgs","repos_url":"https://api.github.com/users/thefourtheye/repos","events_url":"https://api.github.com/users/thefourtheye/events{/privacy}","received_events_url":"https://api.github.com/users/thefourtheye/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nodejs/node/labels/buffer","name":"buffer","color":"f7c6c7"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-10-14T19:32:45Z","updated_at":"2016-10-17T11:24:14Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/nodejs/node/pulls/9101","html_url":"https://github.com/nodejs/node/pull/9101","diff_url":"https://github.com/nodejs/node/pull/9101.diff","patch_url":"https://github.com/nodejs/node/pull/9101.patch"},"body":"##### Checklist\r\n\r\n- [x] `make -j8 test` (UNIX), or `vcbuild test nosign` (Windows) passes\r\n- [x] tests and/or benchmarks are included\r\n- [x] commit message follows commit guidelines\r\n\r\n##### Affected core subsystem(s)\r\n\r\nbuffer\r\n\r\n##### Description of change\r\n\r\nAs shown in https://github.com/nodejs/node/issues/9096, the offset and\r\nend value of the `slice` call are just coerced to numbers and then\r\npassed to `FastBuffer`, which internally truncates the mantissa part\r\nif the number is actually a floating point number. This actually\r\naffects the new length of the slice calculation. For example,\r\n\r\n    > const original = Buffer.from('abcd');\r\n    undefined\r\n    > original.slice(original.length / 3).toString()\r\n    'bc'\r\n\r\nThis happens because, starting value of the slice is 4 / 3, which is\r\n1.33 (approximately). Now, the length of the slice is calculated as\r\nthe difference between the actual length of the buffer and the starting\r\noffset. So, it becomes 2.67 (4 - 1.33). Now, a new `FastBuffer` is\r\nconstructed, with these values, actual buffer object, starting value\r\nwhich is 1.33 and the the length 2.67. The underlying C++ code\r\ntruncates the numbers and they become 1 and 2. That is why the result\r\nis just `bc`.\r\n\r\nThis patch makes sure that all the offsets are coerced to an integer.\r\n\r\nFixes: https://github.com/nodejs/node/issues/9096\r\n\r\n---\r\n\r\ncc @nodejs/buffer "},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/254181288","html_url":"https://github.com/nodejs/node/pull/9101#issuecomment-254181288","issue_url":"https://api.github.com/repos/nodejs/node/issues/9101","id":254181288,"user":{"login":"thefourtheye","id":696611,"avatar_url":"https://avatars.githubusercontent.com/u/696611?v=3","gravatar_id":"","url":"https://api.github.com/users/thefourtheye","html_url":"https://github.com/thefourtheye","followers_url":"https://api.github.com/users/thefourtheye/followers","following_url":"https://api.github.com/users/thefourtheye/following{/other_user}","gists_url":"https://api.github.com/users/thefourtheye/gists{/gist_id}","starred_url":"https://api.github.com/users/thefourtheye/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thefourtheye/subscriptions","organizations_url":"https://api.github.com/users/thefourtheye/orgs","repos_url":"https://api.github.com/users/thefourtheye/repos","events_url":"https://api.github.com/users/thefourtheye/events{/privacy}","received_events_url":"https://api.github.com/users/thefourtheye/received_events","type":"User","site_admin":false},"created_at":"2016-10-17T11:24:14Z","updated_at":"2016-10-17T11:24:14Z","body":"@trevnorris String's slice also works like this only\r\n\r\n```js\r\n> const str = \"abcd\"\r\nundefined\r\n> str.slice(str.length / 3)\r\n'bcd'\r\n> str.slice(str.length / 3, str.length)\r\n'bcd'\r\n```"}}
{"actor":{"display_login":"thefourtheye"}}