Skip to content
Snippets Groups Projects
Commit fa946d4a authored by Jean Chalard's avatar Jean Chalard
Browse files

Fix a test and crash with a better error message when reading

When there are too many bigrams, we stop reading the file,
so the file pointer is in an inconsistent place. This means we
have no idea what's going to happen next. It's better to crash
right away.

Change-Id: Id3b7b78cbe4fda3493b3c9c46758763e1ab5f6a3
parent 74577bed
No related branches found
No related tags found
No related merge requests found
...@@ -169,7 +169,8 @@ public class Ver3DictDecoder extends DictDecoder { ...@@ -169,7 +169,8 @@ public class Ver3DictDecoder extends DictDecoder {
addressPointer += PtNodeReader.readBigramAddresses(mDictBuffer, bigrams, addressPointer += PtNodeReader.readBigramAddresses(mDictBuffer, bigrams,
addressPointer); addressPointer);
if (bigrams.size() >= FormatSpec.MAX_BIGRAMS_IN_A_PTNODE) { if (bigrams.size() >= FormatSpec.MAX_BIGRAMS_IN_A_PTNODE) {
MakedictLog.d("too many bigrams in a PtNode."); throw new RuntimeException("Too many bigrams in a PtNode (" + bigrams.size()
+ " but max is " + FormatSpec.MAX_BIGRAMS_IN_A_PTNODE + ")");
} }
} else { } else {
bigrams = null; bigrams = null;
......
...@@ -224,7 +224,8 @@ public class Ver4DictDecoder extends DictDecoder { ...@@ -224,7 +224,8 @@ public class Ver4DictDecoder extends DictDecoder {
if (0 == (bigramFlags & FormatSpec.FLAG_BIGRAM_SHORTCUT_ATTR_HAS_NEXT)) break; if (0 == (bigramFlags & FormatSpec.FLAG_BIGRAM_SHORTCUT_ATTR_HAS_NEXT)) break;
} }
if (bigrams.size() >= FormatSpec.MAX_BIGRAMS_IN_A_PTNODE) { if (bigrams.size() >= FormatSpec.MAX_BIGRAMS_IN_A_PTNODE) {
MakedictLog.d("too many bigrams in a node."); throw new RuntimeException("Too many bigrams in a PtNode (" + bigrams.size()
+ " but max is " + FormatSpec.MAX_BIGRAMS_IN_A_PTNODE + ")");
} }
} else { } else {
bigrams = null; bigrams = null;
......
...@@ -104,7 +104,9 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { ...@@ -104,7 +104,9 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
} }
sStarBigrams.put(0, new ArrayList<Integer>()); sStarBigrams.put(0, new ArrayList<Integer>());
for (int i = 1; i < sWords.size(); ++i) { // MAX - 1 because we added one above already
final int maxBigrams = Math.min(sWords.size(), FormatSpec.MAX_BIGRAMS_IN_A_PTNODE - 1);
for (int i = 1; i < maxBigrams; ++i) {
sStarBigrams.get(0).add(i); sStarBigrams.get(0).add(i);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment