Skip to content

Commit bbdeeb6

Browse files
test(extract): pin PHP mask copy-on-write via arena allocation total (DeusData#2000)
Signed-off-by: harshitaajoshi <j.harshitaa06@gmail.com>
1 parent 0843106 commit bbdeeb6

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

‎tests/test_extraction.c‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,16 +971,28 @@ TEST(php_inline_html_markup_never_reaches_graph_issue2000) {
971971
}
972972

973973
/* The mask hands back the caller's buffer, uncopied, when nothing needs
974-
* rewriting, and a same-length rewrite otherwise. */
974+
* rewriting, and a same-length rewrite otherwise. The pointer alone cannot
975+
* tell copy-on-write from an eager copy, so the arena's allocation total is
976+
* sampled around each call: no bytes for `plain` and `quoted`, a copy for
977+
* `mixed`. */
975978
TEST(php_inline_html_mask_copies_only_on_write_issue2000) {
976979
CBMArena arena;
977980
cbm_arena_init(&arena);
978981
const char *plain = "<?php\nfunction a() { return 1; }\n";
979982
const char *quoted = "<?php\n$s = '?>';\n/* ?> */\n$h = <<<EOT\n?>\nEOT;\n";
980983
const char *mixed = "<?php\nfunction a() {}\n?>\n<b>x</b>\n";
984+
985+
size_t before = cbm_arena_total(&arena);
981986
ASSERT(cbm_php_mask_inline_html(&arena, plain, (int)strlen(plain)) == plain);
987+
ASSERT_EQ(cbm_arena_total(&arena), before);
988+
989+
before = cbm_arena_total(&arena);
982990
ASSERT(cbm_php_mask_inline_html(&arena, quoted, (int)strlen(quoted)) == quoted);
991+
ASSERT_EQ(cbm_arena_total(&arena), before);
992+
993+
before = cbm_arena_total(&arena);
983994
const char *masked = cbm_php_mask_inline_html(&arena, mixed, (int)strlen(mixed));
995+
ASSERT(cbm_arena_total(&arena) > before);
984996
ASSERT(masked != mixed);
985997
ASSERT_EQ((int)strlen(masked), (int)strlen(mixed));
986998
ASSERT_STR_EQ(masked, "<?php\nfunction a() {}\n; \n \n");

0 commit comments

Comments
 (0)