Repository navigation
4.X: fix bitfield off-by-one encoding - #108
Tejasshack merged 2 commits into
Conversation
Tejasshack
commented
Sep 21, 2026
PR 108 — Fixed Bitfield
-
The encoding change matches the specification.
The spec defines bit 0 as ID 1, bit 1 as ID 2, and so on. The change fromcontainsInt(i)tocontainsInt(i + 1)correctly aligns encoding with the existing decode behavior. This is not a spec issue. -
Actual bug: the last valid ID cannot be stored through the API.
EncodableFixedBitfield.initialize()creates theIntegerSetwithadjustment = 0andto = numElements, so the set only accepts IDs0..numElements-1. After the encoding fix, the valid IDs are1..numElements. -
Example:
ForBitfield(24), IDs1..23work, but ID24is rejected byIntegerSet.addInt()and is never stored. Therefore,Purpose 24cannot be set throughsetFieldValue(). -
Recommended fix:
Initialize the set withadjustment = 1:@Override protected IntegerSet initialize() { return new IntegerSet(new BitSet(numElements), 0, numElements, 1); }
-
Add a boundary round-trip test.
Please verify the highest ID, not only middle values:Set<Integer> purposeConsents = Set.of(1, 24); // encode -> decode -> assert equality
The same boundary check should be added for
Bitfield(12)so Special Feature Opt-In ID12also survivessetFieldValue().
Main point: PR 108 is spec-correct on bit indexing; the remaining issue is an off-by-one storage bug that prevents the highest valid ID from being set.
Specification for reference
https://github.com/InteractiveAdvertisingBureau/Global-Privacy-Platform
yuzawa-san
commented
Sep 22, 2026
@Tejasshack i believe i have applied the desired fixes in my most recent commits. i actually dropped support for IntegerSet with adjustment of 0 (it is now always 1) and the GppModelTest.consistencyTest does the range 1...24 in one of its cases successfully.
Tejasshack
commented
Sep 23, 2026
@yuzawa-san I’ve reviewed the changes. Thanks for adding the fixes. This looks good to me.
@chuff
chuff
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified locally: pulled the branch, ran mvn test (344 tests, 0 failures). The off-by-one fix removes the adjustment abstraction and bakes in 1-based indexing directly in IntegerSet, consistent with every remaining call site (vendor ranges, purpose bitfields, custom-purpose flexible bitfields) which are all 1-indexed per the TCF spec. Boundary case (purpose/vendor 24) round-trips correctly. LGTM.
Co-authored-by: Cursor <cursoragent@cursor.com>
this addresses the feedback done in #83 (comment)
from one of the tcf specs: