Commit 25767146 by eguven Committed by Oliver Woodman

Fix possible failure in CachedContentIndex encrypted cache index file read.

Encryption key in index file is read by DataInputStream.read() which may return less bytes than required. Replaced it with readFully() which should read full length of data.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=140597693
parent 501f54a8
......@@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.upstream.cache;
import android.util.Log;
import android.util.SparseArray;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.upstream.cache.Cache.CacheException;
......@@ -55,6 +56,8 @@ import javax.crypto.spec.SecretKeySpec;
private static final int FLAG_ENCRYPTED_INDEX = 1;
private static final String TAG = "CachedContentIndex";
private final HashMap<String, CachedContent> keyToContent;
private final SparseArray<String> idToKey;
private final AtomicFile atomicFile;
......@@ -224,7 +227,7 @@ import javax.crypto.spec.SecretKeySpec;
return false;
}
byte[] initializationVector = new byte[16];
input.read(initializationVector);
input.readFully(initializationVector);
IvParameterSpec ivParameterSpec = new IvParameterSpec(initializationVector);
try {
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec);
......@@ -245,6 +248,7 @@ import javax.crypto.spec.SecretKeySpec;
return false;
}
} catch (IOException e) {
Log.e(TAG, "Error reading cache content index file.", e);
return false;
} finally {
if (input != null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment