diag: the baseline and corpus files are read like the reports they are

Both files diagnose consumes are written by other runs and pasted
between people: --diagnose-baseline is an earlier report, the corpus a
forwarded file. Neither was read like a supplied file. The baseline got
the unbounded Json::parse, and compare_outputs then walked it with
throwing accessors -- a member it does not expect throws, and nothing
between run_diagnose and main catches -- so a crafted "earlier report"
aborted a run with std::terminate after hours of benchmarking work. The
corpus got a hand-rolled unbounded fread loop and a raw parser per
line: a deep line recursed the parse to a stack overflow before the
fingerprint check could ever run.

Now: capped read and parse_container on both (the corpus's size refusal
lands before the bytes are read), a per-line over/deep refusal that
names the line, and one try around the comparison so any structure the
comparison does not expect is the refusal it should be -- "the baseline
is not shaped like a report", parity not compared, the run keeps its
own results. diagnose_test pins the deep line.

Found by the 2.1.0 review pass (both security axes, independently).
This commit is contained in:
fl0l0u committed 2026-11-15 22:02:27 +00:00
1 parent 5c66eecc8e
commit d893fd05d1
3 files changed
+46 -18

No files matched your search

+8
View File
@@ -464,6 +464,14 @@ TEST(corpus_file_reads_messages_and_prompts) {
TEST(corpus_file_refuses_a_bad_line_and_names_it) {
std::vector<CorpusEntry> c;
std::string why;
{
/* A line nesting past what a prompt line nests: the raw parser recursed for this, and
* the corpus -- a forwarded file -- is exactly the supplied input that stays bounded. */
TmpFile f(std::string("{\"category\": \"c\", \"prompt\": \"x\", \"tail\": ") +
std::string(1200, '[') + std::string(1200, ']') + "}\n");
CHECK_EQ(load_corpus(f.path, &c, &why), RAD_E_INVAL);
CHECK(why.find("nests far too deep") != std::string::npos);
}
{
TmpFile f("{\"category\": \"code\", \"prompt\": \"a\"}\n{\"prompt\": \"no category\"}\n");
CHECK_EQ(load_corpus(f.path, &c, &why), RAD_E_INVAL);