Skip to content

Commit 3632828

Browse files
dfa1claude
andcommitted
refactor(reader): drop redundant offset > fileSize bounds clause
Mutation testing flagged the `offset > fileSize` comparison in both validateSegmentSpecs and checkBlobBounds as an equivalent mutant — changing its boundary never changed an outcome. It is genuinely dead: once `length < 0` is excluded, length >= 0, so an offset past fileSize makes fileSize - offset negative and the final `length > fileSize - offset` clause already fires. The clause can never independently decide the result. This is the same overflow-safe shape as IoBounds.checkRange (which omits the clause); the parser had hand-rolled the guard and drifted from its own primitive. Removing it simplifies both predicates and eliminates the equivalent mutants rather than papering over them with unkillable-by-design tests. Existing bounds tests stay green and keep their context-named messages. Reader mutations 110 -> 106 (4 dead mutants gone), killed 90%. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 35cfddb commit 3632828

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

reader/src/main/java/io/github/dfa1/vortex/reader/PostscriptParser.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ static void validateSegmentSpecs(List<SegmentSpec> specs, long fileSize) {
7878
SegmentSpec s = specs.get(i);
7979
long offset = s.offset();
8080
long length = s.length();
81-
if (offset < 0 || length < 0 || offset > fileSize || length > fileSize - offset) {
81+
// Overflow-safe containment in [0, fileSize], same shape as IoBounds.checkRange. An
82+
// `offset > fileSize` clause would be redundant: with length >= 0 already guaranteed,
83+
// offset > fileSize forces length > fileSize - offset, so the final clause covers it.
84+
if (offset < 0 || length < 0 || length > fileSize - offset) {
8285
throw new VortexException(
8386
"footer segmentSpecs[" + i + "] out of bounds: offset=" + offset
8487
+ " length=" + length + " fileSize=" + fileSize);
@@ -87,7 +90,10 @@ static void validateSegmentSpecs(List<SegmentSpec> specs, long fileSize) {
8790
}
8891

8992
private static void checkBlobBounds(String name, long offset, long length, long fileSize) {
90-
if (offset < 0 || length < 0 || offset > fileSize || length > fileSize - offset) {
93+
// Same overflow-safe range form as IoBounds.checkRange (no redundant `offset > fileSize`
94+
// clause: length >= 0 makes it implied by the final comparison). Keeps the blob-named
95+
// message that checkRange's generic text would lose.
96+
if (offset < 0 || length < 0 || length > fileSize - offset) {
9197
throw new VortexException(
9298
"postscript " + name + " blob out of bounds: offset=" + offset
9399
+ " length=" + length + " fileSize=" + fileSize);

0 commit comments

Comments
 (0)