Fix validator crashes on malformed METS content - #380
Closed
luis100 wants to merge 1 commit into
Closed
Conversation
Several SIP validation checks let exceptions from unchecked METS bean
values or filesystem path resolution escape and crash the whole CLI
run instead of being reported as validation errors:
- StructMapValidator: fileGrp.getUSE() can be null, causing an NPE on
.equals("Representations"); switched to the null-safe comparison.
- EARKSIPValidator/EARKPyIPValidator: mets/metsHdr can be absent from
the XML, causing an NPE when eagerly reading its OAISPACKAGETYPE
before validation runs; now guarded so the missing header is instead
reported by the metsHdr component validator (CSIP117/CSIP9).
- FileSecValidator/DmdSecValidator/AmdSecValidator/StructMapValidator:
resolving a decoded @href/@Label against the IP path throws
InvalidPathException when it contains characters invalid in a
filesystem path (e.g. a NUL byte); now caught and reported as a
validation failure at each call site.
- DecoderUtils.normalizePath: hardened the same way as defense in
depth, since it runs before decoding on every href processed by the
validators above.
- StructValidator.isZipFile: avoid opening the IP path as a
RandomAccessFile when it's already known to be a directory, which
always threw FileNotFoundException and spammed the log with a
misleading stack trace on every folder-mode validation.
Verified against the full erroneous_sips_v2 corpus (51 SIPs, dir + zip
modes): baseline had 5 crashing runs, all now complete with proper
validation reports and no regressions in the other 97.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Several SIP validation checks let exceptions from unchecked METS bean values or filesystem path resolution escape and crash the whole CLI run instead of being reported as a validation error.
StructMapValidator:fileGrp.getUSE()can benull, causing an NPE on.equals("Representations"). Switched to a null-safe comparison (2 call sites).EARKSIPValidator/EARKPyIPValidator:mets/metsHdrcan be absent from the XML, causing an NPE when eagerly reading itsOAISPACKAGETYPEbefore component validation runs. Now guarded, so the missing header is instead reported by the metsHdr component validator (CSIP117/CSIP9), as it already correctly handles this case.FileSecValidator/DmdSecValidator/AmdSecValidator/StructMapValidator: resolving a decoded@href/@labelagainst the IP path viaPaths.resolve(...)throwsInvalidPathExceptionwhen it contains characters invalid in a filesystem path (e.g. a NUL byte embedded in the href). Now caught at every such call site and reported as a proper validation failure instead of crashing.DecoderUtils.normalizePath: hardened the same way as defense in depth, since it runs (pre-decoding) on every href processed by the validators above.StructValidator.isZipFile: avoid opening the IP path as aRandomAccessFilewhen it's already known to be a directory. This previously always threwFileNotFoundExceptionfor every folder-mode validation and spammed the log with a misleading stack trace, even though it was silently caught and handled correctly.Test plan
mvn compile— clean buildmvn test— all 25 existing unit tests passerroneous_sips_v2corpus (51 SIPs, both directory and zip mode = 102 runs):NullPointerException/InvalidPathException), matching a real user-reported bug.INVALIDwith a clear issue message instead of a stack trace.🤖 Generated with Claude Code
https://claude.ai/code/session_011C1rByHgijBMAgvqTnmePS