From 76ead0ead06ab1c09c698247c19d1d2f4bd35d23 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Sat, 23 Feb 2013 01:41:44 -0800 Subject: [PATCH] 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 --- .../inputmethod/latin/BinaryDictionaryGetter.java | 10 +++++++--- 1 file 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(); } /**