Blank row in mpc.gencost reads past the start of the string

未关闭 适合新手
#587 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
88/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
cpp
领域
backend

调研方向

从 GridKit/Model/PowerFlow/MatpowerParser.hpp 中的 readMatPowerGenCostRow 开始,使用包含空行的 mpc.gencost 用例,通过 readMatPower 重现该问题。验证空行不再发生越界读取,而是改为引发 parser 的语法错误;重新运行 clang++ AddressSanitizer 构建,以确认下溢已消失。

由索引模型根据 Issue 内容生成。

描述

Following up on #580, which @pelesh closed asking for an issue with a reproducer and a suggested solution.

readMatPowerGenCostRow in GridKit/Model/PowerFlow/MatpowerParser.hpp checks the last character after trimming:

rtrim(row);
if (row[row.size() - 1] != ';')

A blank line inside mpc.gencost leaves row empty, so row.size() - 1 wraps around and the read goes out of bounds.

Reproducer, driving GridKit::readMatPower with a small case file whose mpc.gencost block starts with an empty line:

mpc.gencost = [

2 0 0 3 0.01 40 0;
];

Built with clang++ -std=c++17 -fsanitize=address -g:

==36380==ERROR: AddressSanitizer: stack-buffer-underflow
    #0 readMatPowerGenCostRow<double, int> MatpowerParser.hpp:156
    #0 readMatPower<int, double, 1028ul> MatpowerParser.hpp:211

The bus, gen and branch row readers take the same line without trouble, since they only read through operator>>, so this is specific to the gencost reader.

Suggested solution: treat an empty row the way a row with the wrong terminator is treated, so the reader raises the parser's own syntax error rather than indexing the string. Something as small as checking for an empty string before looking at the last character is enough; I have that change and the reproducer ready if you would like a PR against it.

主要语言
C++
星标
27
派生
11
平均合并
2 天 21 小时
30 天内合并 PR
15

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ORNL/GridKit 的其他 Issue

查看 ORNL/GridKit 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。