Skip to content

Commit 7f1979d

Browse files
Basic input validation for generating an index from a string
This method gets used by FakeReader to count the number of rows in a plate based on the well name, so input should be the well row label, e.g. "A", "AC".
1 parent e44e4ec commit 7f1979d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

components/formats-bsd/src/loci/formats/ResourceNamer.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,14 @@ public String getLetter() {
139139
public static int alphabeticIndexCount(String index) {
140140
int count = 0;
141141
char[] letters = index.toCharArray();
142+
if (letters.length > 6) {
143+
// this will cause an integer overflow
144+
throw new IllegalArgumentException("Cannot count more than 6 characters");
145+
}
142146
for (int i = 0; i < letters.length; i++) {
143-
count += (letters[i] - 64) * Math.pow(ALPHABET_LENGTH, i);
147+
int letterIndex = (int) Math.pow(ALPHABET_LENGTH, i);
148+
int letterValue = letterIndex * (letters[i] - 64);
149+
count += letterValue;
144150
}
145151
return count;
146152
}

0 commit comments

Comments
 (0)