Skip to content

fix: keep at most 100 schema errors and release the inflater on every path - #19

Merged
marevol merged 1 commit into
fix/limit-xml-nesting-depthfrom
fix/bound-schema-errors-and-release-inflater
Nov 16, 2026
Merged

marevol merged 1 commit into
fix/limit-xml-nesting-depthfrom
fix/bound-schema-errors-and-release-inflater

Conversation

@marevol

@marevol marevol commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Stacked on #18 (the base is that branch; retarget to main once #18 is merged).

Summary

Two costs that an anonymous message can raise before its signature is checked.

  • Schema errors. XMLErrorAccumulatorHandler kept one SAXParseException per error the schema check reported. A document with tens of thousands of invalid elements held tens of megabytes until the check finished, and Util.validateXML then built a string of all of them before cutting it to 1,000 characters for the log. The handler now keeps the first 100 errors, which say what is wrong with the document. hasError() and the validation result are unchanged.
  • Inflater. Util.base64decodedInflated skipped Inflater#end() when inflating failed, so the native memory of the inflater waited for the garbage collector. It is released in a finally block now.

Test

  • UtilsTest#testSchemaErrorsAreKeptUpToALimit: a response with 3,000 invalid elements leaves 100 errors, hasError() is true and validateXML is false. Without the limit the test sees 3,000.
  • UtilsTest#testBase64decodedInflatedOfBytesThatAreNotDeflated: the fallback for a payload that is not deflated data is unchanged.
  • The core module's 430 tests and the toolkit module's 93 tests pass.

… path

XMLErrorAccumulatorHandler kept one SAXParseException for every error
the schema check reported. A message is checked against the schema
before its signature, and a document with tens of thousands of invalid
elements held tens of megabytes until the check finished. The handler
now keeps the first 100 errors; hasError() is unchanged.

Util.base64decodedInflated skipped Inflater#end() when inflating failed,
which left the native memory of the inflater to the garbage collector.
Release it in a finally block.
@marevol
marevol added this pull request to stack #21 November 16, 2026 14:18
@marevol marevol added this to the 3.1.3 milestone Nov 16, 2026
@marevol marevol self-assigned this Nov 16, 2026
@marevol
marevol merged commit 8f8a3da into main Nov 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant