aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAurash Mahbod <aurash@google.com>2014-06-23 23:03:35 -0700
committerAurash Mahbod <aurash@google.com>2014-06-24 15:35:01 -0700
commit5bd5325bd61414480091b262204f1a45d57c1884 (patch)
treeb9a855d553490498fbd796cbbbac8bf4f217c89b /src
parent527f964cc7df8e807deb21469a537a6f6800e0fb (diff)
downloadvolley-5bd5325bd61414480091b262204f1a45d57c1884.tar.gz
Fix crash/OOM in DiskBasedCache
DiskBasedCache.writeHeader() can throw an IOException and swallow it. This causes the cache entry to be partially written followed by the entry's data. When reading back, it is possible to read back the data segment (garbled part) when attempting to parse the cache header. Change-Id: I3022ca1566bc60e5869bb4ec384c866b4ba5c1c5
Diffstat (limited to 'src')
-rw-r--r--src/com/android/volley/toolbox/DiskBasedCache.java9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/com/android/volley/toolbox/DiskBasedCache.java b/src/com/android/volley/toolbox/DiskBasedCache.java
index 2a4761b..d397aad 100644
--- a/src/com/android/volley/toolbox/DiskBasedCache.java
+++ b/src/com/android/volley/toolbox/DiskBasedCache.java
@@ -61,7 +61,7 @@ public class DiskBasedCache implements Cache {
private static final float HYSTERESIS_FACTOR = 0.9f;
/** Magic number for current version of cache file format. */
- private static final int CACHE_MAGIC = 0x20120504;
+ private static final int CACHE_MAGIC = 0x20140623;
/**
* Constructs an instance of the DiskBasedCache at the specified directory.
@@ -197,7 +197,12 @@ public class DiskBasedCache implements Cache {
try {
FileOutputStream fos = new FileOutputStream(file);
CacheHeader e = new CacheHeader(key, entry);
- e.writeHeader(fos);
+ boolean success = e.writeHeader(fos);
+ if (!success) {
+ fos.close();
+ VolleyLog.d("Failed to write header for %s", file.getAbsolutePath());
+ throw new IOException();
+ }
fos.write(entry.data);
fos.close();
putEntry(key, e);