Skip to content

Commit

Permalink
Do not increment loop counter.
Browse files Browse the repository at this point in the history
fixes #1140

DROID is getting stuck in an infinite loop trying to match the right fragments for [this signature](https://github.com/nationalarchives/pronom-signatures/blob/develop/signatures/fmt/134.json#L132)

The steps are something like:

1. It finds matches for 7 of the 8 right fragments.
2. It adds these to a matched list
3. It doesn't find a match for the 8th fragment
4. It then searches each of the fragments in the matched list to either side of the previous matches.
5. Fragments 1-7 match and so stay in the matched list
6. The last matched fragment position is set to 7
7. The loop checking each fragment increments the fragment position to 8
8. It doesn't find a match for the 8th fragment
9. Repeat steps 3 - 9

The problem I think is step 6. It shouldn't be changing the loop counter.

The issue is that I'm not 100% sure if by doing this, we'll be skipping
some fragment checks which will cause a different format to not be
matched at some point in the future.
I don't think so though because the main loop still iterates through
every fragment.
  • Loading branch information
MancunianSam committed Feb 3, 2025
1 parent 36dd409 commit b81e83c
Showing 1 changed file with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1406,18 +1406,13 @@ private long[] bytePosForRightFragments(final WindowReader bytes, final long lef
//Add the newly found fragment instance to the top of the stack and reset the loop
// position to resume checking for further fragments from that point.
tempEndPos[numEndPos] = tempFragEnd + searchDirection;
//CHECKSTYLE:OFF : Quite legitimate to modify control variables here, as we're
// reverting to an earlier fragment!
iFragPos = lastGoodFragRef.getFragmentSignaturePosition();
iAlt = lastGoodFragRef.getAlternativeFragmentNumber();
//CHECKSTYLE:ON
//Get the offset of this new instance of the current fragment from the previous
//fragment, or main sequence if this is the first fragment.
long newOffSetFoundFromPreviousMatch = tempEndPos[numEndPos]
- lastGoodFragRef.getPositionInFile() + lastGoodFragRef.getOffsetFound();
FragmentHit fragmentHit =
new FragmentHit(iFragPos, iAlt, tempEndPos[numEndPos],
newOffSetFoundFromPreviousMatch);
new FragmentHit(lastGoodFragRef.getFragmentSignaturePosition(), lastGoodFragRef.getAlternativeFragmentNumber(), tempEndPos[numEndPos],
newOffSetFoundFromPreviousMatch);
fragmentHits.push(fragmentHit);
numEndPos += 1;

Expand Down

0 comments on commit b81e83c

Please sign in to comment.