StackAsk is a community where developers ask questions, share answers and learn from each others real-world experience, so every solved problem helps the next person who runs into it.
// đây là lớp của chúng ta class A implements Serializable { private static final long serialVersionUID = 2L; String name; String value; }
// đây là lớp của hacker đã xoá mất trường name để nhằm mục tiêu chiếm đoạt giá trị value class A implements Serializable { private static final long serialVersionUID = 2L; String value; }
ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(byteOut); A a = new A(); a.value = "Hello"; out.writeObject(a); byte[] bytes = byteOut.toByteArray();
[-84, -19, 0, 5, 115, 114, 0, 52, 99, 111, 109, 46, 116, 118, 100, 49, 50, 46, 101, 120, 97, 109, 112, 108, 101, 46, 115, 101, 114, 105, 97, 108, 105, 122, 101, 114, 46, 74, 97, 118, 97, 83, 101, 114, 105, 97, 108, 105, 122, 101, 114, 69, 120, 97, 109, 112, 108, 101, 36, 65, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 1, 76, 0, 5, 118, 97, 108, 117, 101, 116, 0, 18, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 83, 116, 114, 105, 110, 103, 59, 120, 112, 116, 0, 5, 72, 101, 108, 108, 111]
ByteArrayInputStream byteIn = new ByteArrayInputStream(bytes); ObjectInputStream in = new ObjectInputStream(byteIn); A a = (A)in.readObject();
public static class A implements Serializable { private static final long serialVersionUID = 3L; public String value; }
Exception in thread "main" java.io.InvalidClassException: com.tvd12.example.serializer.JavaSerializerExample$A; local class incompatible: stream classdesc serialVersionUID = 2, local class serialVersionUID = 3 at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:699) at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:2001) at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1848) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2158) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1665) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:501) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:459) at com.tvd12.example.serializer.JavaSerializerExample.main(JavaSerializerExample.java:26)
2.2K Point(s)
1.2K Point(s)
313 Point(s)
178 Point(s)
138 Point(s)
Your account is signed in on the device(s) below. Sign out of at least one of them to continue signing in on this device.
Your account is signed in on the device(s) below. Sign out directly on one of those devices, or wait until the sign-in again time shown below.
If you cant access those devices, please contact the administrator to sign them out for you.
Input your email to receive reset password link, or if you remember your password, you can click