Skip to content

Commit

Permalink
Catch the StackOverflowError triggered by malformed PKCS#7 signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
ebourg committed Oct 13, 2023
1 parent 87ceabf commit 20b2f85
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion jsign-core/src/main/java/net/jsign/appx/APPXFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public List<CMSSignedData> getSignatures() throws IOException {
}
} catch (UnsupportedOperationException e) {
// unsupported type, just skip
} catch (Exception e) {
} catch (Exception | StackOverflowError e) {
e.printStackTrace();
}
}
Expand Down
2 changes: 1 addition & 1 deletion jsign-core/src/main/java/net/jsign/cat/CatalogFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public List<CMSSignedData> getSignatures() throws IOException {
}
}
}
} catch (CMSException e) {
} catch (CMSException | StackOverflowError e) {
throw new IOException(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public synchronized List<CMSSignedData> getSignatures() throws IOException {
}
}
}
} catch (CMSException | IllegalArgumentException | IllegalStateException | NoSuchElementException | ClassCastException e) {
} catch (CMSException | IllegalArgumentException | IllegalStateException | NoSuchElementException | ClassCastException | StackOverflowError e) {
throw new IOException(e);
}
return signatures;
Expand Down
2 changes: 1 addition & 1 deletion jsign-core/src/main/java/net/jsign/msi/MSIFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public List<CMSSignedData> getSignatures() throws IOException {
}
} catch (UnsupportedOperationException e) {
// unsupported type, just skip
} catch (Exception e) {
} catch (Exception | StackOverflowError e) {
e.printStackTrace();
}
}
Expand Down
2 changes: 1 addition & 1 deletion jsign-core/src/main/java/net/jsign/navx/NAVXFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public List<CMSSignedData> getSignatures() throws IOException {
}
} catch (UnsupportedOperationException e) {
// unsupported type, just skip
} catch (Exception e) {
} catch (Exception | StackOverflowError e) {
e.printStackTrace();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void read(SeekableByteChannel channel) throws IOException {
buffer.get(signatureBytes);
try {
signedData = new CMSSignedData((CMSProcessable) null, ContentInfo.getInstance(new ASN1InputStream(signatureBytes).readObject()));
} catch (CMSException e) {
} catch (CMSException | StackOverflowError e) {
throw new IOException("Invalid CMS signature", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public CMSSignedData getSignature() throws CMSException {
if (signature == null) {
try {
signature = new CMSSignedData((CMSProcessable) null, ContentInfo.getInstance(new ASN1InputStream(content).readObject()));
} catch (IOException e) {
} catch (IOException | StackOverflowError e) {
throw new IllegalArgumentException("Failed to construct ContentInfo from byte[]: ", e);
}
}
Expand Down
2 changes: 1 addition & 1 deletion jsign-core/src/main/java/net/jsign/pe/PEFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ public synchronized List<CMSSignedData> getSignatures() {
}
} catch (UnsupportedOperationException e) {
// unsupported type, just skip
} catch (Exception e) {
} catch (Exception | StackOverflowError e) {
e.printStackTrace();
}
}
Expand Down
4 changes: 2 additions & 2 deletions jsign-core/src/main/java/net/jsign/script/SignableScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public List<CMSSignedData> getSignatures() {
}
} catch (UnsupportedOperationException e) {
// unsupported type, just skip
} catch (Exception e) {
} catch (Exception | StackOverflowError e) {
e.printStackTrace();
}

Expand Down Expand Up @@ -232,7 +232,7 @@ private CMSSignedData decodeSignatureBlock() throws CMSException {

try {
return new CMSSignedData((CMSProcessable) null, ContentInfo.getInstance(new ASN1InputStream(signatureBytes).readObject()));
} catch (IOException e) {
} catch (IOException | StackOverflowError e) {
throw new IllegalArgumentException("Failed to construct ContentInfo from byte[]: ", e);
}
}
Expand Down

0 comments on commit 20b2f85

Please sign in to comment.