提交 d5c04e8f authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Avoid OOME in Transfer.readValue() with large CLOB

上级 6f2cdb4a
...@@ -14,7 +14,6 @@ import java.io.Reader; ...@@ -14,7 +14,6 @@ import java.io.Reader;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
...@@ -463,10 +462,6 @@ public class Transfer { ...@@ -463,10 +462,6 @@ public class Transfer {
throw DbException.get( throw DbException.get(
ErrorCode.CONNECTION_BROKEN_1, "length=" + length); ErrorCode.CONNECTION_BROKEN_1, "length=" + length);
} }
if (length > Integer.MAX_VALUE) {
throw DbException.get(
ErrorCode.CONNECTION_BROKEN_1, "length="+ length);
}
writeLong(length); writeLong(length);
Reader reader = v.getReader(); Reader reader = v.getReader();
Data.copyString(reader, out); Data.copyString(reader, out);
...@@ -652,21 +647,10 @@ public class Transfer { ...@@ -652,21 +647,10 @@ public class Transfer {
return ValueLobDb.create( return ValueLobDb.create(
Value.CLOB, session.getDataHandler(), tableId, id, hmac, precision); Value.CLOB, session.getDataHandler(), tableId, id, hmac, precision);
} }
if (length < 0 || length > Integer.MAX_VALUE) { if (length < 0) {
throw DbException.get( throw DbException.get(
ErrorCode.CONNECTION_BROKEN_1, "length="+ length); ErrorCode.CONNECTION_BROKEN_1, "length="+ length);
} }
DataReader reader = new DataReader(in);
int len = (int) length;
char[] buff = new char[len];
IOUtils.readFully(reader, buff, len);
int magic = readInt();
if (magic != LOB_MAGIC) {
throw DbException.get(
ErrorCode.CONNECTION_BROKEN_1, "magic=" + magic);
}
byte[] small = new String(buff).getBytes(StandardCharsets.UTF_8);
return ValueLobDb.createSmallLob(Value.CLOB, small, length);
} }
Value v = session.getDataHandler().getLobStorage(). Value v = session.getDataHandler().getLobStorage().
createClob(new DataReader(in), length); createClob(new DataReader(in), length);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论