Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ private int getLength() throws IOException {
int n = derInputStream.read(bytes);
if (n < num) throw new IOException("Invalid DER: length too short");

return new BigInteger(1, bytes).intValue();
int len = new BigInteger(1, bytes).intValue();
if (len < 0) {
throw new IOException("Invalid DER: length larger than max-int");
}

return len;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ public void testExtractWithMalformedDerData() {
assertThat(result, is(nullValue()));
}

public void testSeqLengthOutOfSignedIntRange() {
byte[] malformedBytes = {
(byte) 48, // SEQUENCE
(byte) 0x84, // Length byte indicating (1) long form with (2) 4 data bytes
(byte) 0xFF,
(byte) 0xFF,
(byte) 0xFF,
(byte) 0xFF };

String result = RdnFieldExtractor.extract(malformedBytes, OID_CN);
assertThat(result, is(nullValue()));
}

public void testExtractWithSpecialCharacters() {
assertExtractions("CN=Test\\, User, OU=R\\+D, O=Elastic\\\\Co", Map.of(OID_CN, "Test, User", OID_OU, "R+D", OID_O, "Elastic\\Co"));
}
Expand Down