Summary
Severity: HIGH
Category: Format string bug / parser logic failure
Location: experimental/utility/LAGraph_DIMACSMaxFlowRead.c lines 84, 99, 125
Trigger
Any valid DIMACS max-flow file, e.g.:
Root Cause
The parser calls scanf(buff, ...) where buff is a line read from the file. scanf reads from stdin and treats buff as the format string, not as the source of data. There are three distinct issues:
- Line 84:
scanf(buff, "p max %" PRIu64 " %" PRIu64, &n_nodes, &n_edges) — buff is used as the format string; should be sscanf.
- Line 99: Passes
which instead of &which for the %c conversion → undefined behavior.
- Line 125: Declares
w as GrB_Index (uint64_t) but uses %d/PRId32 format specifier → type mismatch UB.
// Line 84 — WRONG: buff is used as a format string, reads from stdin
int result = scanf(buff, "p max %" PRIu64 " %" PRIu64, &n_nodes, &n_edges);
// Should be:
int result = sscanf(buff, "p max %" PRIu64 " %" PRIu64, &n_nodes, &n_edges);
Proof / Trace
fgets reads "p max 2 1\n" into buff.
- Line 84 calls
scanf("p max 2 1\n", ...) — no conversion specifiers in buff, so zero values are assigned.
result != 2, so every valid DIMACS file is rejected.
- If
buff happens to contain % characters (valid in DIMACS comments), it controls the format string and causes undefined behavior.
Impact
The parser is completely non-functional for all valid DIMACS input. Files containing % in comment lines trigger format-string undefined behavior.
Suggested Fix
Replace all three scanf calls with sscanf. Fix the missing & on the which argument at line 99. Use a correctly-typed temporary for the parsed weight on line 125.
Summary
Severity: HIGH
Category: Format string bug / parser logic failure
Location:
experimental/utility/LAGraph_DIMACSMaxFlowRead.clines 84, 99, 125Trigger
Any valid DIMACS max-flow file, e.g.:
Root Cause
The parser calls
scanf(buff, ...)wherebuffis a line read from the file.scanfreads from stdin and treatsbuffas the format string, not as the source of data. There are three distinct issues:scanf(buff, "p max %" PRIu64 " %" PRIu64, &n_nodes, &n_edges)—buffis used as the format string; should besscanf.whichinstead of&whichfor the%cconversion → undefined behavior.wasGrB_Index(uint64_t) but uses%d/PRId32format specifier → type mismatch UB.Proof / Trace
fgetsreads"p max 2 1\n"intobuff.scanf("p max 2 1\n", ...)— no conversion specifiers inbuff, so zero values are assigned.result != 2, so every valid DIMACS file is rejected.buffhappens to contain%characters (valid in DIMACS comments), it controls the format string and causes undefined behavior.Impact
The parser is completely non-functional for all valid DIMACS input. Files containing
%in comment lines trigger format-string undefined behavior.Suggested Fix
Replace all three
scanfcalls withsscanf. Fix the missing&on thewhichargument at line 99. Use a correctly-typed temporary for the parsed weight on line 125.