Merge "Make readHeader check the header size before using it."
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
index e2fa023..e0874bb 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
@@ -1683,13 +1683,14 @@
         final HashMap<String, String> attributes = new HashMap<String, String>();
         final int headerSize;
         headerSize = buffer.readInt();
-        populateOptions(buffer, headerSize, attributes);
-        buffer.position(headerSize);
 
         if (headerSize < 0) {
             throw new UnsupportedFormatException("header size can't be negative.");
         }
 
+        populateOptions(buffer, headerSize, attributes);
+        buffer.position(headerSize);
+
         final FileHeader header = new FileHeader(headerSize,
                 new FusionDictionary.DictionaryOptions(attributes,
                         0 != (optionsFlags & FormatSpec.GERMAN_UMLAUT_PROCESSING_FLAG),