find method in Packer.java does not find all words
Brought to you by:
orasis
In the find method of Packer.java the break statement
occurs too early; because of this, the last word in a
block may not be found. This may lead to easy passwords
being erroneously recognised as safe.
The correct for-loop in find has to look like this:
for (;;) {
int middle = lwm + ((hwm - lwm + 1) / 2);
int cmp = s.compareTo(get(middle));
if ( cmp == 0 )
return middle;
if ( hwm == middle ) break;
if \(cmp < 0\) \{
hwm = middle;
} else {
lwm = middle;
}
}
This still fails if the word is the first of only 2 items in a list (lwm = 0, hwm = 1).
Putting the following before the for(;;) loop fixes the issue though: -
Although we could alter the population of hwms array to remove the need for this though.
Last edit: Peter Jamieson 2015-12-16