IABTechLab / iabgpp-java

Apache License 2.0
11 stars 13 forks source link

This *might be an issue #23

Closed ym-corey closed 5 months ago

ym-corey commented 1 year ago

I noticed while including some tests in my code, that sometimes under conditions I haven't worked out yet, the GppModel's TcfEuV2 can decode to a different value... Not sure if this is the only case that something like this happens.

There is a difference between the fromObjectModel and decodedModel, being that the header section isn't present in the former. However, my understanding is that when the other sections of the GPP string change, the section for TcfEuV2, delimited by ~, should remain unchanged.

  public static void main(String[] args) throws EncodingException, DecodingException {
    var fromObjectModel = new GppModel();

    fromObjectModel.setFieldValue(TcfEuV2.NAME, TcfEuV2Field.PURPOSE_CONSENTS, new ArrayList<>(List.of(true, true, true, true, true, true, true, true, true, true)));
    fromObjectModel.setFieldValue(TcfEuV2.NAME, TcfEuV2Field.VENDOR_CONSENTS, new ArrayList<>(List.of(32,128,81,210,755,21,173,238)));

    System.out.println(fromObjectModel.getSection(TcfEuV2.NAME).encode());
    System.out.println(fromObjectModel.getSection(TcfEuV2.NAME).encode());
    System.out.println(fromObjectModel.encode());

    var decodedModel = new GppModel(fromObjectModel.encode());

    System.out.println(decodedModel.getSection(TcfEuV2.NAME).encode());
    System.out.println(decodedModel.encode());
  }

Results:

CPl0blNPl0blNAAAAAENAACAAP_AAAAAAAAAB3QCAAKgAgACiAIAAVoA0gB3ALzAAAAA.QAAA.IAAA
CPl0blNPl0blNAAAAAENAACAAP_AAAAAAAAAF5wCAAKgAgACiAIAAVoA0gB3ALzAAAAA.QAAA.IAAA
DBABMA~CPl0blNPl0blNAAAAAENAACAAP_AAAAAAAAAF5wCAAKgAgACiAIAAVoA0gB3ALzAAAAA.QAAA.IAAA
CPl0blNPl0blNAAAAAENAACAAP_AAAAAAAAAF5wCAAKgAgACiAIAAVoA0gB3ALzAAAAA.QAAA.IAAA
DBABMA~CPl0blNPl0blNAAAAAENAACAAP_AAAAAAAAAF5wCAAKgAgACiAIAAVoA0gB3ALzAAAAA.QAAA.IAAA

The first and second printout should be the same, but are not. The third printout should include the first value, after the delimiter, but it doesn't -- it is the 2nd value after the delimiter.

I have noticed that the values for TcfEuV2Field.SPECIAL_FEATURE_OPTINS and TcfEuV2Field.PURPOSE_LEGITIMATE_INTERESTS are empty in fromObjectModel and are non-empty (contain arrays filled with false) in decodedModel, but even when setting the values to the same thing I still see different consent strings.

e.g.,

    fromObjectModel.setFieldValue(TcfEuV2.NAME, TcfEuV2Field.SPECIAL_FEATURE_OPTINS, new ArrayList<>(List.of(false, false, false, false, false, false, false, false, false, false, false, false)));
    fromObjectModel.setFieldValue(TcfEuV2.NAME, TcfEuV2Field.PURPOSE_LEGITIMATE_INTERESTS, new ArrayList<>(List.of(false, false, false, false, false, false, false, false, false, false,
                                                                                                                   false, false, false, false, false, false, false, false, false, false, false, false, false, false)));
chuff commented 1 year ago

Confirmed that this is a bug related to encoding optimized ranges. The first 16 bits are allocated to a size value, which is correct in the first but wrong in the second. Fix incoming...

chuff commented 1 year ago

Fixed in 3.0.10. And I was wrong in my last comment. The second one was actually correct.