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
This commit is contained in:
eguven 2016-11-30 06:23:47 -08:00 committed by Oliver Woodman
parent 501f54a8a6
commit 257671467f

View file

@ -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) {