Skip to content

java.lang.OutOfMemoryError: Java heap space when decoding non GPP string #44

@alex-ro

Description

@alex-ro

Add the following test in GppModelTest.java file.

  // java.lang.OutOfMemoryError: Java heap space
  @Test
  public void testDecodingExceptionValidStringButNotGPP() {
    try {
      GppModel gppModel = new GppModel("CP48G0AP48G0AEsACCPLAkEgAAAAAEPgAB5YAAAQaQD2F2K2kKFkPCmQWYAQBCijYEAhQAAAAkCBIAAgAUgQAgFIIAgAIFAAAAAAAAAQEgCQAAQABAAAIACgAAAAAAIAAAAAAAQQAAAAAIAAAAAAAAEAAAAAAAQAAAAIAABEhCAAQQAEAAAAAAAQAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAgAA");
      Assertions.fail("Expected LazyDecodingException");
    } catch (DecodingException e) {

    }
  }

The proposed solution is to validate the first 2 numbers in the header of the message, to fail fast if the string is not GPP.
So, in HeaderV1.java:

  private static final String ID_BITSTRING = "000011";
  private static final String VERSION_BITSTRING = "000001";
  private static final String HEADER_PREFIX_BITSTRING = ID_BITSTRING + VERSION_BITSTRING;
  @Override
  public void decode(String encodedString) throws DecodingException {
    String bitString = base64UrlEncoder.decode(encodedString);
    if (!bitString.startsWith(HEADER_PREFIX_BITSTRING)) {
      throw new DecodingException("Not GPP v1 string");
    };
    this.decodeFromBitString(bitString);
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions