hessian 反序列化问题
有class 比如
class Test{
private TestArrayList list=new TestArrayList("");
public static void main(String args[]){
Test t=new Test();
byte[] b=hessian encode ;
Test r =(Test)hessian decode
}
}
class TestArrayList extends ArrayList{
public TestArrayList(String a){}
}
反序列化后Test对象里的list不再是TestArrayList,而是 ArrayList类型
分析hessian反序列化源码
Hessian2Input.java
public Object readObject(Class cl){
//省略
case 0x70: case 0x71: case 0x72: case 0x73:
case 0x74: case 0x75: case 0x76: case 0x77:
{
int length = tag - 0x70;
String type = readType();
Deserializer reader;
reader = findSerializerFactory().getListDeserializer(type, cl);
//关键处
Object v = reader.readLengthList(this, length);
return v;
}
}
跳转到
CollectionDeserializer.java
public Object readLengthList(AbstractHessianInput in, int length)
throws IOException
{
Collection list = createList(); in.addRef(list); for (; length > 0; length--)
list.add(in.readObject()); return list;
} private Collection createList()
throws IOException
{
Collection list = null; if (_type == null)
list = new ArrayList();
else if (! _type.isInterface()) {
try {
//关键处
list = (Collection) _type.newInstance();
} catch (Exception e) {
}
} if (list != null) {
}
else if (SortedSet.class.isAssignableFrom(_type))
list = new TreeSet();
else if (Set.class.isAssignableFrom(_type))
list = new HashSet();
else if (List.class.isAssignableFrom(_type))
list = new ArrayList();
else if (Collection.class.isAssignableFrom(_type))
list = new ArrayList();
//省略
}
list = (Collection) _type.newInstance();尝试调用TestArrayList的无参构造函数,但因为没有无参构造函数,抛出异常,走到下面的list = new ArrayList();逻辑 我们看看newInstance()做了什么事情
public T newInstance()
throws InstantiationException, IllegalAccessException
{
if (System.getSecurityManager() != null) {
checkMemberAccess(Member.PUBLIC, Reflection.getCallerClass(), false);
} // NOTE: the following code may not be strictly correct under
// the current Java memory model. // Constructor lookup
if (cachedConstructor == null) {
if (this == Class.class) {
throw new IllegalAccessException(
"Can not call newInstance() on the Class for java.lang.Class"
);
}
try {
Class<?>[] empty = {};
final Constructor<T> c = getConstructor0(empty, Member.DECLARED);
//省略
} private Constructor<T> getConstructor0(Class<?>[] parameterTypes,
int which) throws NoSuchMethodException
{
Constructor<T>[] constructors = privateGetDeclaredConstructors((which == Member.PUBLIC));
//这里parameterTypes是空数组,constructors不为空
for (Constructor<T> constructor : constructors) {
//数组比较长度不一致,抛出异常
if (arrayContentsEq(parameterTypes,
constructor.getParameterTypes())) {
return getReflectionFactory().copyConstructor(constructor);
}
}
throw new NoSuchMethodException(getName() + ".<init>" + argumentTypesToString(parameterTypes));
}
因此我们如果调用hessian序列化对象的时候,一定要注意对象里面的自定义属性是否有默认构造函数,不然会引起奇怪的问题
hessian 反序列化问题的更多相关文章
- Spring boot 集成hessian - LocalDateTime序列化和反序列化
- 反序列化 import com.caucho.hessian.HessianException; import com.caucho.hessian.io.AbstractDeserializer ...
- 【CVE-2020-1948】Apache Dubbo Provider反序列化漏洞复现
一.实验简介 实验所属系列: 系统安全 实验对象:本科/专科信息安全专业 相关课程及专业: 计算机网络 实验时数(学分):2 学时 实验类别: 实践实验类 二.实验目的 Apache Dubbo是一款 ...
- dubbo 官方参考手册~备案(防止哪天阿里一生气把dubbo给删除了)
首页 || 下载 || 用户指南 || 开发者指南 || 管理员指南 || 培训文档 || 常见问题解答 || 发布记录 || 发展路线 || 社区 E ...
- Hessian 序列化和反序列化实现
先聊聊 Java的序列化,Java官方的序列化和反序列化的实现被太多人吐槽,这得归于Java官方序列化实现的方式. 1.Java序列化的性能经常被吐槽.2.Java官方的序列化后的数据相对于一些优秀的 ...
- 测试Hessian反序反序列化 客户端少字段和多字段时能否成功
import java.io.*; import com.caucho.hessian.io.HessianInput; import com.caucho.hessian.io.HessianOut ...
- Xml,Json,Hessian,Protocol Buffers序列化对比
简介 这篇博客主要对Xml,Json,Hessian,Protocol Buffers的序列化和反序列化性能进行对比,Xml和Json的基本概念就不说了. Hessian:Hessian是一个轻量级的 ...
- Hessian 原理分析--转
原文地址:http://blog.csdn.net/zhtang0526/article/details/4788879 一. 远程通讯协议的基本原理 网络通信需要做的就是将流从一台计算机传 ...
- Hessian 初探
Hessian 是一个序列化协议, 他的优点在于比 Java 原生的对象序列化/反序列化速度更快, 序列化出来以后的数据更小. 序列化协议跟应用层协议无关, 可以将 Hessian 序列化以后的数据放 ...
- Hessian原理分析
一. 远程通讯协议的基本原理 网络通信需要做的就是将流从一台计算机传输到另外一台计算机,基于传输协议和网络 IO 来实现,其中传输协议比较出名的有 http . tcp . udp 等等, ...
随机推荐
- 03 事务,连接池DBCP,C3P0,DBUtils
事务 Transaction 其实指的一组操作,里面包含许多个单一的逻辑.只要有一个逻辑没有执行成功,那么都算失败. 所有的数据都回归到最初的状态(回滚) 事务的作用:为了确保逻辑的成功. 例子: ...
- 02 http,servlet,servletconfig,HttpServletRequest ,HttpServletResponse
Http协议 协议:双方在交互.通讯的时候, 遵守的一种规范.规则.http协议:针对网络上的客户端 与 服务器端在执行http请求的时候,遵守的一种规范. 其实就是规定了客户端在访问服务器端的时候, ...
- C++ 作业(哈夫曼树)
#include<bits/stdc++.h> #define fi first #define se second #define int long long using namespa ...
- 【NOI2014】【BZOJ3669】【UOJ#3】魔法森林
我学会lct辣 原题: 为了得到书法大家的真传,小E同学下定决心去拜访住在魔法森林中的隐士.魔法森林可以被看成一个包含个N节点M条边的无向图,节点标号为 1…n1…n,边标号为1…m1…m.初始时小E ...
- hibernate中Restrictions的用法
方法 说明 Restrictions.eq = Restrictions.allEq 利用Map来进行多个等于的限制 Restrictions.gt > Restrictions.ge > ...
- Gravitational Teleport docker-compose组件独立部署运行
Gravitational Teleport 可以作为堡垒机进行使用,上次写过一个all in one 的,这次参考官方 的配置运行一个proxy node auth 分离的应用 备注: 基于dock ...
- python结合redis模拟队列
实在无聊就写了个很小的python程序用来实现模拟redis队列的代码如下: redis_lpush.py #!/usr/bin/python3 import time import redis ...
- ML(2)——感知器
感知器(PLA——Perceptron Learning Algorithm),也叫感知机,处理的是机器学习中的分类问题,通过学习得到感知器模型来对新实例进行预测,因此属于判别模型.感知器于1957年 ...
- c#与C++类型转换网摘
转载自 C++和C#转换 https://www.cnblogs.com/zjoch/p/4147182.html c#与C++类型转换,网摘 //c++:HANDLE(void *) ...
- pdf.js 的使用
现在的浏览器基本都支持直接把 pdf 文件拖到浏览器就可以打开,不用下载pdf阅读插件,但是在写网页的时候遇到了 pdf 文件怎么办呢,有两种解决办法,一种是用 falsh 来向用户展示,优点就是支持 ...