Skip to content

Commit

Permalink
Throw exceptions when headers contain unrecognized flags
Browse files Browse the repository at this point in the history
  • Loading branch information
ehrmann committed Jun 4, 2017
1 parent dc0b552 commit 41369e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ public DeltaWindowHeader parseWinIndicatorAndSourceSegment(
return null;
}

int unrecognized_flags = win_indicator & 0xff & ~(VCD_SOURCE | VCD_TARGET);
if (unrecognized_flags != 0) {
LOGGER.warn(String.format("Unrecognized win_indicator flags: 0x%02x", unrecognized_flags));
}

int source_target_flags = win_indicator & (VCD_SOURCE | VCD_TARGET);
switch (source_target_flags) {
case VCD_SOURCE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,17 +462,25 @@ private int readDeltaFileHeader(ByteBuffer data) throws IOException {
}
if (data_size < DeltaFileHeader.SERIALIZED_SIZE) return RESULT_END_OF_DATA;
}

int unrecognizedFlags = header.hdr_indicator & 0xff & ~(VCD_DECOMPRESS | VCD_CODETABLE);
if (unrecognizedFlags != 0) {
throw new IOException(String.format("Unrecognized hdr_indicator flags: %02x", unrecognizedFlags));
}

// Secondary compressor not supported.
if ((header.hdr_indicator & VCD_DECOMPRESS) != 0) {
throw new IOException("Secondary compression is not supported");
}

if ((header.hdr_indicator & VCD_CODETABLE) != 0) {
int bytes_parsed = InitCustomCodeTable(data.array(), data.arrayOffset() + data.position() + DeltaFileHeader.SERIALIZED_SIZE,
data.remaining() - DeltaFileHeader.SERIALIZED_SIZE);
if (bytes_parsed == RESULT_END_OF_DATA) {
return RESULT_END_OF_DATA;
}
data.position(data.position() + DeltaFileHeader.SERIALIZED_SIZE + bytes_parsed);
// TODO unknown flags on hdr_indicator
} else {
addrCache = new VCDiffAddressCacheImpl();
// addrCache->init() will be called
Expand Down

0 comments on commit 41369e3

Please sign in to comment.