@@ -341,6 +341,54 @@ TEST(parallel_empty_files) {
341341 PASS ();
342342}
343343
344+ /* ── Regression: args JSON must not overflow the props buffer ──────── */
345+
346+ /* A call with many long string arguments makes append_args_json()'s running
347+ * position exceed the fixed CBM_SZ_2K `props` stack buffer in
348+ * emit_normal_calls_edge(): format_call_arg() returns snprintf's UNtruncated
349+ * length, so pos += n could run past the buffer and the trailing
350+ * buf[pos]='\0' wrote out of bounds (stack-buffer-overflow; caught by the
351+ * stack canary as a SIGABRT on real repos). This indexes a fixture whose
352+ * single call carries enough long args to drive pos past 2 KB; under the
353+ * ASan test build a regression aborts here. */
354+ TEST (parallel_args_json_no_overflow ) {
355+ char dir [256 ];
356+ snprintf (dir , sizeof (dir ), "/tmp/cbm_argov_XXXXXX" );
357+ ASSERT_TRUE (cbm_mkdtemp (dir ) != NULL );
358+
359+ char path [512 ];
360+ snprintf (path , sizeof (path ), "%s/app.ts" , dir );
361+ FILE * f = fopen (path , "w" );
362+ ASSERT_TRUE (f != NULL );
363+ fputs ("function sink(...xs: string[]) { return xs; }\n" , f );
364+ fputs ("function caller() {\n sink(\n" , f );
365+ for (int i = 0 ; i < 60 ; i ++ ) {
366+ /* 100-char string literal per arg; 60 args => args JSON well past the
367+ * 2 KB props buffer, forcing the pre-fix overshoot. */
368+ fputs (" \"" , f );
369+ for (int j = 0 ; j < 100 ; j ++ )
370+ fputc ('a' + (i % 26 ), f );
371+ fputs (i < 59 ? "\",\n" : "\"\n" , f );
372+ }
373+ fputs (" );\n}\n" , f );
374+ fclose (f );
375+
376+ cbm_discover_opts_t opts = {.mode = CBM_MODE_FULL };
377+ cbm_file_info_t * files = NULL ;
378+ int file_count = 0 ;
379+ ASSERT_EQ (cbm_discover (dir , & opts , & files , & file_count ), 0 );
380+ ASSERT_GT (file_count , 0 );
381+
382+ cbm_gbuf_t * gbuf = run_parallel ("argov-test" , dir , files , file_count , 4 );
383+ ASSERT_TRUE (gbuf != NULL );
384+ ASSERT_GT (cbm_gbuf_edge_count (gbuf ), 0 );
385+
386+ cbm_gbuf_free (gbuf );
387+ cbm_discover_free (files , file_count );
388+ th_rmtree (dir );
389+ PASS ();
390+ }
391+
344392/* ── Graph buffer merge tests ─────────────────────────────────────── */
345393
346394TEST (gbuf_shared_ids_unique ) {
@@ -680,6 +728,7 @@ SUITE(parallel) {
680728 RUN_TEST (parallel_implements_parity );
681729 RUN_TEST (parallel_total_edges );
682730 RUN_TEST (parallel_empty_files );
731+ RUN_TEST (parallel_args_json_no_overflow );
683732
684733 /* Cleanup shared state */
685734 parity_teardown ();
0 commit comments