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

Aperta Adatta ai principianti
#587 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
88/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
backend

Direzione di ricerca

Iniziare in GridKit/Model/PowerFlow/MatpowerParser.hpp, in readMatPowerGenCostRow, e riprodurre il problema tramite readMatPower usando il caso mpc.gencost con una riga vuota. Verificare che la riga vuota non legga più oltre i limiti e che invece generi l'errore di sintassi del parser; eseguire nuovamente la build clang++ con AddressSanitizer per confermare che l'underflow sia scomparso.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
C++
Stelle
27
Fork
11
Merge medio
2g 21h
PR unite (30g)
15

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ORNL/GridKit

Tutte le issue di ORNL/GridKit

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.