HdrHistogramJS icon indicating copy to clipboard operation
HdrHistogramJS copied to clipboard

Fix integer overflows in AssemblyScript & Typescript implementations

Open lcallarec opened this issue 4 years ago • 4 comments

Hey,

This PR fixes an integer overflow issue in both AssemblyScript & Typescript implementations.

In short : on an unsigned integer, when overflow occurs, the value won't be read as a negative integer.

Please note that in the current implementation, the user could create an Histogram with a signed internal bucket of type IntXArray ; an issue will also occurs and this PR doesn't fix that case. :)

Note also that I didn't find a way to test the assembly version in assembly folder : the tested method throws, and it seems that try / catch aren't supported yet

lcallarec avatar Nov 17 '20 08:11 lcallarec

Thanks a lot for the PR! I guess there might be an issue with "record value with count" methods as well

alexvictoor avatar Nov 17 '20 12:11 alexvictoor

You're right : overflows may produce wrong counts when :

  • addition and subtraction of histograms
  • decoding an histogram as a smaller sized one.

I'll take a look.

lcallarec avatar Nov 17 '20 23:11 lcallarec

I guess all remaining overflow issues have been fixed with last commits.

lcallarec avatar Nov 19 '20 12:11 lcallarec

Sorry @MaxGraey, I don't know what happend, looks like I did something that deleted your commit proposal (or there was a github issue) with my comment... I was saying that the bitwise shift operation won't work as is. maxBucketSize is typed as number to avoid TS2365: Operator '>' cannot be applied to types 'f64' and 'i64' compiler errors.

So I guess that we should writethis.maxBucketSize = ((1 << (<i8>sizeof<U>() * 8)) - 1) as number;. What do you think ?

lcallarec avatar Nov 20 '20 08:11 lcallarec