From 257671467f6c97762f473c42709aecdd28d149bc Mon Sep 17 00:00:00 2001 From: eguven Date: Wed, 30 Nov 2016 06:23:47 -0800 Subject: [PATCH] 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 --- .../exoplayer2/upstream/cache/CachedContentIndex.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/com/google/android/exoplayer2/upstream/cache/CachedContentIndex.java b/library/src/main/java/com/google/android/exoplayer2/upstream/cache/CachedContentIndex.java index d8224665b9..a4a97b4332 100644 --- a/library/src/main/java/com/google/android/exoplayer2/upstream/cache/CachedContentIndex.java +++ b/library/src/main/java/com/google/android/exoplayer2/upstream/cache/CachedContentIndex.java @@ -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 keyToContent; private final SparseArray 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) {