HyperLogLogPlusPlus fails on serializeToByteArray
- Dominant language
- Java
- Stars
- 169
- Forks
- 23
- PR merge metrics
- No merged PRs in 30d
Description
In [Scio](https://github.com/spotify/scio) we have the following error thrown on version *0.1.0*. Unfortunately it is unclear how to reproduce, and I can't provide input data. But stack trace suggests that there is something wrong with management of array slices in `com.google.zetasketch.internal.GrowingByteSlice`:
```
16:04:53.990 [info] java.lang.IllegalArgumentException: 19 > 5
16:04:53.990 [info] at Due to Exception while trying to `encode` an instance of com.spotify.data.dm.sources.internal.AudienceEngagementMetrics: Can't encode field listeners value com.spotify.scio.extra.hll.zetasketch.ZetaSketchHll@151901cb.(:0)
16:04:53.990 [info] at java.base/java.util.Arrays.copyOfRange(Arrays.java:4029)
16:04:53.990 [info] at com.google.zetasketch.internal.GrowingByteSlice.maybeExtendLimit(GrowingByteSlice.java:219)
16:04:53.990 [info] at com.google.zetasketch.internal.GrowingByteSlice.putNextVarInt(GrowingByteSlice.java:191)
16:04:53.990 [info] at com.google.zetasketch.internal.GrowingByteSlice.putNextVarInt(GrowingByteSlice.java:30)
16:04:53.990 [info] at com.google.zetasketch.internal.DifferenceEncoder.putInt(DifferenceEncoder.java:54)
16:04:53.990 [info] at com.google.zetasketch.internal.hllplus.SparseRepresentation.set(SparseRepresentation.java:424)
16:04:53.990 [info] at com.google.zetasketch.internal.hllplus.SparseRepresentation.flushBuffer(SparseRepresentation.java:348)
16:04:53.990 [info] at com.google.zetasketch.internal.hllplus.SparseRepresentation.compact(SparseRepresentation.java:243)
16:04:53.990 [info] at com.google.zetasketch.HyperLogLogPlusPlus.serializeToByteArray(HyperLogLogPlusPlus.java:298)
16:04:53.990 [info] at com.spotify.scio.extra.hll.zetasketch.ZetaSketchHll$$anonfun$coder$2.apply(ZetaSketchHLL.scala:121)
16:04:53.990 [info] at com.spotify.scio.extra.hll.zetasketch.ZetaSketchHll$$anonfun$coder$2.apply(ZetaSketchHLL.scala:121)
```
So it fails on `array = Arrays.copyOfRange(array, arrayOffset(), Math.max(growthCapacity, limit));` and there might be something wrong with `Math.max(growthCapacity, limit)`, apparently it is out of boundaries
Contributor guide
Assessment
This issue has not been assessed yet.