ensure there is enough data available for a DD
@@ -932,7 +932,8 @@ private boolean bufferContainsSignature(final ByteArrayOutputStream bos, final i
for (int i = 0; !done && i < offset + lastRead - 4; i++) {
if (buf.array()[i] == LFH[0] && buf.array()[i + 1] == LFH[1]) {
int expectDDPos = i;
- if ((buf.array()[i + 2] == LFH[2] && buf.array()[i + 3] == LFH[3])
+ if (i >= expectedDDLen &&
+ (buf.array()[i + 2] == LFH[2] && buf.array()[i + 3] == LFH[3])
|| (buf.array()[i] == CFH[2] && buf.array()[i + 3] == CFH[3])) {
// found a LFH or CFH:
expectDDPos = i - expectedDDLen;
