aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-02-23 01:41:44 -0800
committerJean Chalard <jchalard@google.com>2013-02-23 01:41:44 -0800
commit76ead0ead06ab1c09c698247c19d1d2f4bd35d23 (patch)
treefeb91cc7f51f268aa6ec3afd940552ca89298ac2
parentaefaec3c5fc4b9aa3126ae0a7f32133c0423e7e2 (diff)
downloadlatinime-76ead0ead06ab1c09c698247c19d1d2f4bd35d23.tar.gz
latinime-76ead0ead06ab1c09c698247c19d1d2f4bd35d23.tar.xz
latinime-76ead0ead06ab1c09c698247c19d1d2f4bd35d23.zip
Fix a possible crash
If the dictionary ID, as indicated in the metadata, is less than three chars long, it crashes LatinIME. Of course we don't have such dictionary IDs in the current metadata, but it's still better to be able to handle the case gracefully ^^; Change-Id: I60cdf6f8ecce9f4d44b42ddd5d157aebff9a4163
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java10
1 files changed, 7 insertions, 3 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
index a96738b3e..e913f2852 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
@@ -68,9 +68,13 @@ final class BinaryDictionaryGetter {
/**
* Generates a unique temporary file name in the app cache directory.
*/
- public static String getTempFileName(String id, Context context) throws IOException {
- return File.createTempFile(DictionaryInfoUtils.replaceFileNameDangerousCharacters(id),
- null).getAbsolutePath();
+ public static String getTempFileName(final String id, final Context context)
+ throws IOException {
+ final String safeId = DictionaryInfoUtils.replaceFileNameDangerousCharacters(id);
+ // If the first argument is less than three chars, createTempFile throws a
+ // RuntimeException. We don't really care about what name we get, so just
+ // put a three-chars prefix makes us safe.
+ return File.createTempFile("xxx" + safeId, null).getAbsolutePath();
}
/**