You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug found with AddressSanitizer, for the unittest with this code:
```
GCBits bits;
bits.alloc(10000);
auto data = bits.data;
GCBits src;
src.alloc(67);
src.data[0] = 0x4;
bits.copyRangeRepeating(2, 10000, src.data, 67); <---- triggers the bug
```
The bug happens for the loop iteration in copyRangeRepeating that calls copyRange where these are the values of variables in copyRange:
cntWords = 2
target = 1342
last = 1408
lastWord = 22
lastOff = 0
firstOff = 62
len = 67
Overread happens on `source[cntWords]`.
Proof of correctness of this fix:
Let's assume `firstOff == 3`, then `source[cntWords] << firstOff` has value `0bxx...xxxxx000` in bits.
For `lastOff == 2`, then `mask = (BITS_2 << lastOff) - 1 == (2 << lastOff) - 1 == 0b1000 - 1 == 0b111`. `src&mask` would always be 0.
For `lastOff == 3`, then `mask = 0b1111`. `src&mask` would be 0bx000, i.e. actual bits of the value read would be used.
0 commit comments