已合并
Fix unbounded stream parameter buffering #433
liyangx创建于 7月28日
Fix unbounded stream parameter buffering #433
已合并
Pull Request已成功合入, 合并人@opengauss_bot
(感谢 liyangx 的贡献)7月28日 添加了label:sig/Connectors
opengauss_bot
7月28日 评论:
7月28日 评论:
Welcome To openGauss Community
Hey @liyangx , thanks for your contribution to the community.
Bot Usage Manual
I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands.
Contact Guide
If you have any questions, please contact the SIG: Connectors ,
and any of the maintainers: @CarrotGo, @chendong76, @chenxiaobin19, @congzhou2603, @dodders, @hwworkholic, @jemappellehc, @muyulinzhong, @quemingjian, @shenzheng4, @shirley_zhengx, @superlchf, @totaj, @wlff234, @wofanzheng, @ywzq1161327784 ,
and any of the committers: @hw_hbj, @libiao2024, @zhangxubo .


7月28日 添加了label:ci-pipeline-running
7月28日 添加了label:codecheck-running
此处折叠了352条消息 查看更多
8月4日 添加了label:codecheck-running
opengauss_bot
8月4日 评论:
8月4日 评论:
opengauss_bot
8月4日 评论:
8月4日 评论:
8月4日 添加了label:codecheck-success
8月4日 删除了label:codecheck-running
【标题】(请简要描述下实现的内容)
Fix unbounded stream parameter buffering
【实现内容】:
修复 PgPreparedStatement 无长度流参数绑定时可能将输入流完整缓存到堆内存,导致大对象/恶意流触发堆内存耗尽的问题。
【根因分析】:
报告指出,部分无长度流参数绑定路径会在执行前将 InputStream/Reader 数据读入内存缓存。对于未声明长度或超大长度的流,调用方可传入任意大小数据,驱动侧缺少明确上限或流式绑定路径,存在堆内存耗尽风险。
【实现方案】:
对 setBinaryStream(int, InputStream) 不再通过 ByteArrayOutputStream 全量拷贝输入流。
对字符流/CLOB 绑定路径做差异化处理。
增加可配置上限。
补充回归测试。
【关联需求或issue】:
https://gitcode.com/opengauss/openGauss-connector-jdbc/issues/680
【开发自验报告】:
已补充以下 JDBC 回归测试用例,覆盖本次修复场景:
见【开发自验报告】
已补充测试用例
不涉及
不涉及
不涉及
已考虑。
不涉及
需考虑
不涉及
【当前PR是否有AI参与】:
[x] 否
[] 是
__1. AI Agent 平台:
__2. AI 模型:
__3. Prompt上下文 :
【其他说明】:
考虑历史兼容性和默认安全边界,本次未简单禁止无长度流参数绑定,而是优先将可流式处理的 binary stream、extended query mode character/CLOB 路径改为流式绑定;仅对 simple query mode 下协议层必须缓存为字符串的场景增加可配置上限。
默认值设置为 16MB。原因是该限制单位为字符数,Java 字符为 16-bit,simple query mode 下还会产生 StringBuilder、String、SQL 拼接等额外对象;若默认设置为 64MB,实际堆内存压力可能明显放大,不适合作为默认值。对于确实需要更大 simple-mode 字符流/CLOB 的业务,可以通过 maxBufferedStreamParameterChars 显式调大。
该上限为连接级可配置参数,默认 16MB。用户如需兼容更大的 simple query mode 字符流/CLOB 绑定场景,可在创建连接时通过 JDBC URL、Properties 或 DataSource 的 setMaxBufferedStreamParameterChars 方法显式调大,例如设置为 67108864 表示 64MB。
①JDBC URL:
②Properties:
Properties props = new Properties(); props.setProperty("maxBufferedStreamParameterChars", "67108864"); Connection conn = DriverManager.getConnection(url, props);③DataSource:
PGSimpleDataSource ds = new PGSimpleDataSource(); ds.setMaxBufferedStreamParameterChars(67108864); Connection conn = ds.getConnection();