Loading core/java/com/android/internal/os/PowerStats.java +8 −1 Original line number Diff line number Diff line Loading @@ -473,9 +473,16 @@ public final class PowerStats { } finally { // Unconditionally skip to the end of the written data, even if the actual parcel // format is incompatible if (endPos > parcel.dataPosition()) { if (endPos >= parcel.dataSize()) { throw new IndexOutOfBoundsException( "PowerStats end position: " + endPos + " is outside the parcel bounds: " + parcel.dataSize()); } parcel.setDataPosition(endPos); } } } /** * Formats the stats as a string suitable to be included in the Battery History dump. Loading core/tests/coretests/src/com/android/internal/os/PowerStatsTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -168,6 +168,20 @@ public class PowerStatsTest { assertThat(end).isEqualTo("END"); } @Test public void parceling_corruptParcel() { PowerStats stats = new PowerStats(mDescriptor); Parcel parcel = Parcel.obtain(); stats.writeToParcel(parcel); Parcel newParcel = marshallAndUnmarshall(parcel); newParcel.writeInt(-42); // Negative section length newParcel.setDataPosition(0); PowerStats newStats = PowerStats.readFromParcel(newParcel, mRegistry); assertThat(newStats).isNull(); } private static Parcel marshallAndUnmarshall(Parcel parcel) { byte[] bytes = parcel.marshall(); parcel.recycle(); Loading Loading
core/java/com/android/internal/os/PowerStats.java +8 −1 Original line number Diff line number Diff line Loading @@ -473,9 +473,16 @@ public final class PowerStats { } finally { // Unconditionally skip to the end of the written data, even if the actual parcel // format is incompatible if (endPos > parcel.dataPosition()) { if (endPos >= parcel.dataSize()) { throw new IndexOutOfBoundsException( "PowerStats end position: " + endPos + " is outside the parcel bounds: " + parcel.dataSize()); } parcel.setDataPosition(endPos); } } } /** * Formats the stats as a string suitable to be included in the Battery History dump. Loading
core/tests/coretests/src/com/android/internal/os/PowerStatsTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -168,6 +168,20 @@ public class PowerStatsTest { assertThat(end).isEqualTo("END"); } @Test public void parceling_corruptParcel() { PowerStats stats = new PowerStats(mDescriptor); Parcel parcel = Parcel.obtain(); stats.writeToParcel(parcel); Parcel newParcel = marshallAndUnmarshall(parcel); newParcel.writeInt(-42); // Negative section length newParcel.setDataPosition(0); PowerStats newStats = PowerStats.readFromParcel(newParcel, mRegistry); assertThat(newStats).isNull(); } private static Parcel marshallAndUnmarshall(Parcel parcel) { byte[] bytes = parcel.marshall(); parcel.recycle(); Loading