Add comments to unexhaustive parsing method

This commit is contained in:
Paul Schaub 2022-05-05 11:15:19 +02:00
parent 69f84f24b6
commit 826331917f
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
1 changed files with 4 additions and 0 deletions

View File

@ -111,6 +111,7 @@ public class OpenPgpInputStream extends BufferedInputStream {
} }
private void nonExhaustiveParseAndCheckPlausibility(ByteArrayInputStream bufferIn) throws IOException { private void nonExhaustiveParseAndCheckPlausibility(ByteArrayInputStream bufferIn) throws IOException {
// Read the packet header
int hdr = bufferIn.read(); int hdr = bufferIn.read();
if (hdr < 0 || (hdr & 0x80) == 0) { if (hdr < 0 || (hdr & 0x80) == 0) {
return; return;
@ -121,6 +122,7 @@ public class OpenPgpInputStream extends BufferedInputStream {
int bodyLen = 0; int bodyLen = 0;
boolean partial = false; boolean partial = false;
// Determine the packet length
if (newPacket) { if (newPacket) {
tag = hdr & 0x3f; tag = hdr & 0x3f;
@ -157,10 +159,12 @@ public class OpenPgpInputStream extends BufferedInputStream {
} }
} }
// Negative body length -> garbage
if (bodyLen < 0) { if (bodyLen < 0) {
return; return;
} }
// Try to unexhaustively parse the first packet bit by bit and check for plausibility
BCPGInputStream bcpgIn = new BCPGInputStream(bufferIn); BCPGInputStream bcpgIn = new BCPGInputStream(bufferIn);
switch (tag) { switch (tag) {
case RESERVED: case RESERVED: