已关闭
[Bug]: sparsevec_in 存在堆缓冲区溢出(heap-buffer-overflow):非零元素超过 SPARSEVEC_MAX_NNZ(16000) 时越界写 #8488
fang_erj创建于  9月8日关闭于  9月14日
fang_erj
fang_erj
9月8日 创建

测试类型

安全

测试版本

7.0.0-RC2

问题描述

openGauss 的 sparsevec 类型文本输入函数 sparsevec_in(src/common/backend/utils/adt/sparsevec.cpp)存在堆缓冲区溢出(越界写)。任意具有连接权限的数据库用户,通过 一条 SQL 语句 即可触发,导致内存破坏 / 服务进程中止(远程可达的拒绝服务 DoS)。

sparsevec_in 中临时数组 elements 的大小与溢出保护使用不一致的表达式:

  • 分配:elements = palloc(Min(maxNnz, SPARSEVEC_MAX_NNZ) * sizeof(...)),上限 16000 条目(第 201 行)
  • 保护:if (nnz == maxNnz),使用 未封顶 的 maxNnz(逗号数 + 1,此处为 20000)(第 227 行)

当非零元素 > 16000 时,nnz 越过 16000 不会触发保护,elements[16000] 越界写(第 291 行)。

操作系统和硬件信息

openEuler release 24.03 (LTS)
Linux openeuler-2403 6.6.0-28.0.0.34.oe2403.x86_64 #1 SMP Mon May 27 22:22:46 CST 2024 x86_64 x86_64 x86_64 GNU/Linux
(硬件:x86_64,4 核 / 7.5 GiB 内存)

测试环境

轻量版服务器安装

被测功能

sparsevec 数据类型文本输入函数 sparsevec_in(datavec 数据向量模块)

预置条件

无

操作步骤

客户端链接并执行:

SELECT '{1:1,2:1,...,20000:1}/20000'::sparsevec;

预期输出

正常接受执行或报错返回

实际输出

连接断开、整个服务器被中止(openGauss 为线程模型,单条连接即可令整库退出)。

日志信息

==39987==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x63400009fc28
WRITE of size 4 at 0x63400009fc28 thread T33
    #0 0x19f4de2 in sparsevec_in(FunctionCallInfoData*) .../adt/sparsevec.cpp:291
0x63400009fc28 is located 0 bytes to the right of 128040-byte region [...)
SUMMARY: AddressSanitizer: heap-buffer-overflow .../sparsevec.cpp:291 in sparsevec_in

提单组织

社区用户

测试代码

likedislike
opengauss_bot
opengauss_bot成员
9月8日 评论:

This issue requires an assignee. Since you haven't specified one, we've assigned TestManager as the default assignee for this issue.

likedislike
opengauss_botopengauss_bot成员
9月8日 将 TestManager 设为负责人
opengauss_bot
opengauss_bot成员
9月8日 评论:

Welcome To openGauss Community

Hey @fang_erj , 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. You can self-configure the PR merge rules for this repository. For more details, please refer to Here.

Contact Guide

If you have any questions, please contact the SIG: StorageEngine, AI, CM, CloudNative, SecurityTechnology, SQLEngine ,
and any of the maintainers: @CarrotGo, @chendong76, @chenxiaobin19, @congzhou2603, @dodders, @hwworkholic, @jemappellehc, @libiao2024, @muyulinzhong, @quemingjian, @shenzheng4, @shirley_zhengx, @superlchf, @totaj, @wlff234, @wofanzheng, @ywzq1161327784 ,
and any of the committers: @Igali, @bihua111, @cailei19, @h_ray, @levy53071, @libiao2024, @lihaixiao, @mrzack, @wangfeihuo, @wuyuechuan, @xiong_xjun, @zhangfengzhi123, @zhangxubo, @zhangzq131, @zjh_hw .

likedislike
opengauss_botopengauss_bot成员
9月8日 添加了label:sig/SQLEngine
fang_erjfang_erj
9月8日 关联了pull request:修复 sparsevec_in 存在堆缓冲区溢出
liuzhen001liuzhen001成员
9月9日 关联了看板:openGauss 7.0.0-LTS
chendong76chendong76成员
9月10日 将 wangjingyuan8 设为负责人
chendong76chendong76成员
9月10日 移除了负责人 TestManager
opengauss_botopengauss_bot成员
9月10日 关闭了 issue
wangjingyuan8wangjingyuan8成员
9月10日 关联了pull request:【回合7.0】Fix heap-buffer-overflow in sparsevec_in when input has more than SPARSEVEC_MAX_NNZ non-zero elements
wangjingyuan8
wangjingyuan8成员
9月12日 评论:

B023验证:
不会有element数组越界写
image.png

likedislike
wangjingyuan8wangjingyuan8成员
9月12日 issue状态由 待办的 改变为 待回归
wangjingyuan8wangjingyuan8成员
9月12日 重新打开了 issue
lvlintao666
lvlintao666成员
9月14日 评论:

回归时间:2026.9.14
回归版本:7.0.0 B023
回归结论:通过
回归步骤:按上述步骤执行SQL语句
select ('{' || string_agg(i||':1',',' order by i )||'}/20000')::sparsevec from generate_series(1,20000) as i;
image.png

likedislike
lvlintao666lvlintao666成员
9月14日 issue状态由 待回归 改变为 已验收
lvlintao666lvlintao666成员
9月14日 关闭了 issue
wangjingyuan8
wangjingyuan8成员
4 天前 评论:

8.0.0B001版本自验证:
6aecf4a5-0b48-47d8-b691-31244d31e2c8.png

likedislike
lvlintao666
lvlintao666成员
2 天前 评论:

回归时间:2026.10.12
回归版本:8.0.0 B001
回归结论:通过
回归步骤:按上述步骤执行SQL语句
image.png

likedislike