Fix padding oracle in CachedContentIndex

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=196838184
This commit is contained in:
eguven 2018-05-16 09:22:37 -07:00 committed by Andrew Lewis
parent 24b16f3419
commit 7d76685e60

View File

@ -15,7 +15,6 @@
*/ */
package com.google.android.exoplayer2.upstream.cache; package com.google.android.exoplayer2.upstream.cache;
import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import com.google.android.exoplayer2.upstream.cache.Cache.CacheException; import com.google.android.exoplayer2.upstream.cache.Cache.CacheException;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
@ -26,7 +25,6 @@ import java.io.BufferedInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
@ -53,8 +51,6 @@ import javax.crypto.spec.SecretKeySpec;
private static final int FLAG_ENCRYPTED_INDEX = 1; private static final int FLAG_ENCRYPTED_INDEX = 1;
private static final String TAG = "CachedContentIndex";
private final HashMap<String, CachedContent> keyToContent; private final HashMap<String, CachedContent> keyToContent;
private final SparseArray<String> idToKey; private final SparseArray<String> idToKey;
private final AtomicFile atomicFile; private final AtomicFile atomicFile;
@ -248,13 +244,12 @@ import javax.crypto.spec.SecretKeySpec;
add(cachedContent); add(cachedContent);
hashCode += cachedContent.headerHashCode(version); hashCode += cachedContent.headerHashCode(version);
} }
if (input.readInt() != hashCode) { int fileHashCode = input.readInt();
boolean isEOF = input.read() == -1;
if (fileHashCode != hashCode || !isEOF) {
return false; return false;
} }
} catch (FileNotFoundException e) {
return false;
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Error reading cache content index file.", e);
return false; return false;
} finally { } finally {
if (input != null) { if (input != null) {