ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject [14/29] ignite git commit: GG-12132 Added magic header to protect from unexpected input.
Date Wed, 26 Apr 2017 09:31:35 GMT
GG-12132 Added magic header to protect from unexpected input.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e4a926b2
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e4a926b2
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e4a926b2

Branch: refs/heads/ignite-5024
Commit: e4a926b2825eee507e1f58a3c1b19fdc2ac80cb4
Parents: 26c222b
Author: Alexey Kuznetsov <akuznetsov@apache.org>
Authored: Tue Apr 25 14:02:26 2017 +0700
Committer: Alexey Kuznetsov <akuznetsov@apache.org>
Committed: Tue Apr 25 14:02:26 2017 +0700

----------------------------------------------------------------------
 .../marshaller/optimized/OptimizedMarshaller.java    |  3 ++-
 .../internal/visor/VisorDataTransferObject.java      | 15 +++++++++++++--
 .../internal/visor/binary/VisorBinaryMetadata.java   |  3 +--
 .../visor/cache/VisorCacheConfiguration.java         |  3 +--
 4 files changed, 17 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/e4a926b2/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshaller.java
b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshaller.java
index 3f40d63..575c9a4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshaller.java
@@ -232,7 +232,8 @@ public class OptimizedMarshaller extends AbstractNodeNameAwareMarshaller
{
                 "[clsLdr=" + clsLdr + ", cls=" + e.getMessage() + "]", e);
         }
         catch (Exception e) {
-            throw new IgniteCheckedException("Failed to deserialize object with given class
loader: " + clsLdr, e);
+            throw new IgniteCheckedException("Failed to deserialize object with given class
loader: " +
+                "[clsLdr=" + clsLdr + ", err=" + e.getMessage() + "]", e);
         }
         finally {
             OptimizedObjectStreamRegistry.closeIn(objIn);

http://git-wip-us.apache.org/repos/asf/ignite/blob/e4a926b2/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorDataTransferObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorDataTransferObject.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorDataTransferObject.java
index d8dcf4e..bdf01e7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorDataTransferObject.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/VisorDataTransferObject.java
@@ -30,6 +30,9 @@ import org.jetbrains.annotations.Nullable;
  * Base class for data transfer objects.
  */
 public abstract class VisorDataTransferObject implements Externalizable {
+    /** Magic number to detect correct transfer objects. */
+    private static final int MAGIC = 0x42BEEF00;
+
     /**
      * @param col Source collection.
      * @param <T> Collection type.
@@ -59,7 +62,9 @@ public abstract class VisorDataTransferObject implements Externalizable
{
 
     /** {@inheritDoc} */
     @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeByte(getProtocolVersion());
+        int hdr = MAGIC  + getProtocolVersion();
+
+        out.writeInt(hdr);
 
         try (VisorDataTransferObjectOutput dtout = new VisorDataTransferObjectOutput(out))
{
             writeExternalData(dtout);
@@ -78,7 +83,13 @@ public abstract class VisorDataTransferObject implements Externalizable
{
 
     /** {@inheritDoc} */
     @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
-        byte ver = in.readByte();
+        int hdr = in.readInt();
+
+        if ((hdr & MAGIC) != MAGIC)
+            throw new IOException("Unexpected VisorDataTransferObject header " +
+                "[actual=" + Integer.toHexString(hdr) + ", expected=" + Integer.toHexString(MAGIC)
+ "]");
+
+        byte ver = (byte)(hdr & 0xFF);
 
         try (VisorDataTransferObjectInput dtin = new VisorDataTransferObjectInput(in)) {
             readExternalData(ver, dtin);

http://git-wip-us.apache.org/repos/asf/ignite/blob/e4a926b2/modules/core/src/main/java/org/apache/ignite/internal/visor/binary/VisorBinaryMetadata.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/binary/VisorBinaryMetadata.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/binary/VisorBinaryMetadata.java
index 5e948c6..285bff9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/binary/VisorBinaryMetadata.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/binary/VisorBinaryMetadata.java
@@ -124,8 +124,7 @@ public class VisorBinaryMetadata extends VisorDataTransferObject {
     }
 
     /** {@inheritDoc} */
-    @Override protected void readExternalData(byte protoVer,
-        ObjectInput in) throws IOException, ClassNotFoundException {
+    @Override protected void readExternalData(byte protoVer, ObjectInput in) throws IOException,
ClassNotFoundException {
         typeName = U.readString(in);
         typeId = (Integer)in.readObject();
         affinityKeyFieldName = U.readString(in);

http://git-wip-us.apache.org/repos/asf/ignite/blob/e4a926b2/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfiguration.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfiguration.java
index 391b120..5b5d3a8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfiguration.java
@@ -418,8 +418,7 @@ public class VisorCacheConfiguration extends VisorDataTransferObject {
     }
 
     /** {@inheritDoc} */
-    @Override protected void readExternalData(byte protoVer,
-        ObjectInput in) throws IOException, ClassNotFoundException {
+    @Override protected void readExternalData(byte protoVer, ObjectInput in) throws IOException,
ClassNotFoundException {
         name = U.readString(in);
         mode = CacheMode.fromOrdinal(in.readByte());
         atomicityMode = CacheAtomicityMode.fromOrdinal(in.readByte());


Mime
View raw message