fastjson '\x' 导致内存溢出

测试代码:

import java.net.URLDecoder;

import org.junit.Test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;

import junit.framework.TestCase;

public class TT extends TestCase {

    final String DEATH_STRING = "{\"a\":\"\\x";

    @Test
    public void test_OOM() throws Exception {

        String line = new String(
                "[{\\x22a\\x22:\\x22a\\xB1ph.\\xCD\\x86\\xBEI\\xBA\\xC3\\xBCiM+\\xCE\\xCE\\x1E\\xDF7\\x1E\\xD9z\\xD9Q\\x8A}\\xD4\\xB2\\xD5\\xA0y\\x98\\x08@\\xE1!\\xA8\\xEF^\\x0D\\x7F\\xECX!\\xFF\\x06IP\\xEC\\x9F[\\x85;\\x02\\x817R\\x87\\xFB\\x1Ch\\xCB\\xC7\\xC6\\x06\\x8F\\xE2Z\\xDA^J\\xEB\\xBCF\\xA6\\xE6\\xF4\\xF7\\xC1\\xE3\\xA4T\\x89\\xC6\\xB2\\x5Cx]");
        line = line.replaceAll("\\\\x", "%");
        String decodeLog = URLDecoder.decode(line, "UTF-8");
        System.out.println(decodeLog);
        try {
            Object obj = JSON.parse(decodeLog);
            obj = JSON.parse(DEATH_STRING);
        } catch (Exception e) {
            assertEquals(e.getClass(), JSONException.class);
            assertTrue(e.getMessage().contains("invalid escape character \\x"));
            e.printStackTrace();
        }
    }
}

pom.xml


	com.alibaba
	fastjson
	1.2.59

fastjson '\x' 导致内存溢出_第1张图片
更改 fastjson


	com.alibaba
	fastjson
	1.2.60

fastjson '\x' 导致内存溢出_第2张图片

参考文章:https://www.anquanke.com/post/id/185909

你可能感兴趣的:(Java基础)