OSDN Git Service

Recover from corrupt network stats.
authorJeff Sharkey <jsharkey@android.com>
Thu, 11 Jul 2013 18:18:53 +0000 (11:18 -0700)
committerThe Android Automerger <android-build@android.com>
Fri, 12 Jul 2013 00:22:41 +0000 (17:22 -0700)
When encountering corrupt stats, throw as IOException to allow
recovery at a higher level.

Bug: 9794832
Change-Id: I38d000b3bd8a4c99389c40a87ee0699efb6e9049

core/java/android/net/NetworkStatsHistory.java

index 382b25e..62d8738 100644 (file)
@@ -639,6 +639,7 @@ public class NetworkStatsHistory implements Parcelable {
         @Deprecated
         public static long[] readFullLongArray(DataInputStream in) throws IOException {
             final int size = in.readInt();
+            if (size < 0) throw new ProtocolException("negative array size");
             final long[] values = new long[size];
             for (int i = 0; i < values.length; i++) {
                 values[i] = in.readLong();
@@ -680,6 +681,7 @@ public class NetworkStatsHistory implements Parcelable {
         public static long[] readVarLongArray(DataInputStream in) throws IOException {
             final int size = in.readInt();
             if (size == -1) return null;
+            if (size < 0) throw new ProtocolException("negative array size");
             final long[] values = new long[size];
             for (int i = 0; i < values.length; i++) {
                 values[i] = readVarLong(in);