Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1065)

Unified Diff: mojo/public/java/bindings/src/org/chromium/mojo/bindings/Decoder.java

Issue 519673002: mojo: Fixing array serialization for java bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Follow review Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/java/bindings/src/org/chromium/mojo/bindings/Decoder.java
diff --git a/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Decoder.java b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Decoder.java
index 8295c5eed3202d0a3efa2a81b6adbecdce7f280a..d716084d0f573157c67359e06d0f6c03bb82534a 100644
--- a/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Decoder.java
+++ b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Decoder.java
@@ -66,6 +66,9 @@ public class Decoder {
}
public void claimMemory(long start, long end) {
+ if (start % BindingsHelper.ALIGNMENT != 0) {
+ throw new DeserializationException("Incorrect starting alignment: " + start + ".");
+ }
if (start < mMinNextMemory) {
throw new DeserializationException("Trying to access memory out of order.");
}
@@ -75,10 +78,7 @@ public class Decoder {
if (end > mMaxMemory) {
throw new DeserializationException("Trying to access out of range memory.");
}
- if (start % BindingsHelper.ALIGNMENT != 0 || end % BindingsHelper.ALIGNMENT != 0) {
- throw new DeserializationException("Incorrect alignment.");
- }
- mMinNextMemory = end;
+ mMinNextMemory = BindingsHelper.align(end);
}
}
@@ -111,17 +111,17 @@ public class Decoder {
mMessage.buffer.order(ByteOrder.nativeOrder());
mBaseOffset = baseOffset;
mValidator = validator;
- // Claim the memory for the header.
- mValidator.claimMemory(mBaseOffset, mBaseOffset + DataHeader.HEADER_SIZE);
}
/**
* Deserializes a {@link DataHeader} at the given offset.
*/
public DataHeader readDataHeader() {
+ // Claim the memory for the header.
+ mValidator.claimMemory(mBaseOffset, mBaseOffset + DataHeader.HEADER_SIZE);
int size = readInt(DataHeader.SIZE_OFFSET);
int numFields = readInt(DataHeader.NUM_FIELDS_OFFSET);
- // The memory for the header has already been claimed.
+ // Claim the remaining memory.
mValidator.claimMemory(mBaseOffset + DataHeader.HEADER_SIZE, mBaseOffset + size);
DataHeader res = new DataHeader(size, numFields);
return res;

Powered by Google App Engine
This is Rietveld 408576698