leptris 1.9.427.0-arm-linux → 1.9.429.0-arm-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/leptris/version.rb +1 -1
- data/lib/leptris/xml/native.so +0 -0
- data/lib/leptris/xml/native_3_3.so +0 -0
- data/lib/libleptris.so +0 -0
- data/vendor-src/README.md +1 -1
- data/vendor-src/libleptris/CHANGELOG.md +28 -0
- data/vendor-src/libleptris/CMakeLists.txt +1 -1
- data/vendor-src/libleptris/scripts/verify_manifest.py +11 -3
- data/vendor-src/libleptris/src/leptris/encoding/wrapper.c +13 -3
- data/vendor-src/libleptris/src/leptris/leptris_internal.h +19 -0
- data/vendor-src/libleptris/src/leptris/rng/parse.c +21 -5
- data/vendor-src/libleptris/src/leptris/rng/validate.c +136 -44
- data/vendor-src/libleptris/src/leptris/xpath/evaluator.c +59 -19
- data/vendor-src/libleptris/src/leptris/xpath/evaluator_operators.c +83 -25
- data/vendor-src/libleptris/src/leptris/xpath/parser.c +24 -0
- data/vendor-src/libleptris/src/leptris/xslt/xslt_exec.c +16 -0
- data/vendor-src/libleptris/src/leptris/xslt/xslt_internal.h +6 -0
- data/vendor-src/libleptris/test/differential/README.md +9 -0
- data/vendor-src/libleptris/test/differential/package.json +1 -1
- data/vendor-src/libleptris/test/differential/rs-runner/Cargo.toml +1 -1
- data/vendor-src/libleptris/test/fuzz/corpus/encoding_decl_strstr_hbo.bin +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/html_tree_amplification_timeout.bin +0 -0
- data/vendor-src/libleptris/test/fuzz/corpus/xpath_bracket_nesting_stack_overflow.bin +0 -0
- data/vendor-src/libleptris/test/fuzz/corpus/xslt_apply_identity_recursion.bin +0 -0
- data/vendor-src/libleptris/test/fuzz/corpus/xslt_mixed_set_dispose_uaf.bin +0 -0
- data/vendor-src/libleptris/test/fuzz/generators/gen_html_seeds.py +101 -0
- data/vendor-src/libleptris/test/fuzz/generators/gen_xml_seeds.py +132 -0
- data/vendor-src/libleptris/test/fuzz/generators/gen_xpath_seeds.py +123 -0
- data/vendor-src/libleptris/test/rng/test_rng.cpp +165 -0
- data/vendor-src/libleptris/test/xpath/test_xpath.cpp +77 -0
- data/vendor-src/libleptris/test/xpath/test_xslt.cpp +80 -0
- data/vendor-src/libleptris/vcpkg.json +1 -1
- metadata +10 -2
|
@@ -241,7 +241,12 @@ XPathNodeSet* xpath_map_items_over(XPathContext* ctx, XPathNodeSet* ns,
|
|
|
241
241
|
XPathASTNode* expr) {
|
|
242
242
|
XPathNodeSet* out = xpath_nodeset_new();
|
|
243
243
|
if (!out) return NULL;
|
|
244
|
-
|
|
244
|
+
/* The owns flags assert facts about EVERY member of the kind —
|
|
245
|
+
* this loop appends raw document nodes (the nodeset branch), so
|
|
246
|
+
* the text flag moves to the synth-append branch below. An
|
|
247
|
+
* eager flag over mixed members made apply_predicates' dispose
|
|
248
|
+
* free document-owned text nodes (SOTA C1, nightly
|
|
249
|
+
* 44085294402). */
|
|
245
250
|
size_t n = ns ? ns->count : 0;
|
|
246
251
|
struct leptris_element* saved_node = ctx->context_node;
|
|
247
252
|
size_t saved_pos = ctx->context_position;
|
|
@@ -281,7 +286,10 @@ XPathNodeSet* xpath_map_items_over(XPathContext* ctx, XPathNodeSet* ns,
|
|
|
281
286
|
XPathTextNode* tn =
|
|
282
287
|
synth_text(piece ? piece : "", piece ? strlen(piece) : 0);
|
|
283
288
|
free(piece);
|
|
284
|
-
if (tn)
|
|
289
|
+
if (tn) {
|
|
290
|
+
xpath_nodeset_add(out, tn);
|
|
291
|
+
out->owns_synthetic_text = 1;
|
|
292
|
+
}
|
|
285
293
|
}
|
|
286
294
|
xpath_result_free(item);
|
|
287
295
|
}
|
|
@@ -1003,6 +1011,10 @@ struct leptris_xpath_result* evaluate_operator(XPathContext* ctx,
|
|
|
1003
1011
|
return NULL;
|
|
1004
1012
|
}
|
|
1005
1013
|
out->owns_synthetic_text = 1;
|
|
1014
|
+
/* Safe despite the raw element adds below: only TEXT/ATTR/NS
|
|
1015
|
+
* members are ever disposed and every non-element member here
|
|
1016
|
+
* is synth-wrapped — the raw members are exclusively ELEMENT
|
|
1017
|
+
* nodes. */
|
|
1006
1018
|
out->is_sequence = 1;
|
|
1007
1019
|
|
|
1008
1020
|
XPathNodeSet* ns =
|
|
@@ -1100,6 +1112,10 @@ struct leptris_xpath_result* evaluate_operator(XPathContext* ctx,
|
|
|
1100
1112
|
XPathNodeSet* one = xpath_nodeset_new();
|
|
1101
1113
|
if (!one) break;
|
|
1102
1114
|
if (ns) {
|
|
1115
|
+
/* Document node: the var set owns nothing (the
|
|
1116
|
+
* ownership flag asserts a fact about every member —
|
|
1117
|
+
* a lie here made the unbind dispose a document
|
|
1118
|
+
* node, SOTA C1 nightly 44085294402). */
|
|
1103
1119
|
xpath_nodeset_add(one, ns->nodes[i]);
|
|
1104
1120
|
} else {
|
|
1105
1121
|
char* sv = xpath_to_string(domain);
|
|
@@ -1114,17 +1130,21 @@ struct leptris_xpath_result* evaluate_operator(XPathContext* ctx,
|
|
|
1114
1130
|
XPathTextNode* tn =
|
|
1115
1131
|
synth_text(marked, sl + 2);
|
|
1116
1132
|
free(marked);
|
|
1117
|
-
if (tn)
|
|
1133
|
+
if (tn) {
|
|
1134
|
+
xpath_nodeset_add(one, tn);
|
|
1135
|
+
one->owns_synthetic_text = 1;
|
|
1136
|
+
}
|
|
1118
1137
|
}
|
|
1119
1138
|
free(sv);
|
|
1120
1139
|
} else {
|
|
1121
1140
|
XPathTextNode* tn =
|
|
1122
1141
|
synth_text(sv ? sv : "", sv ? strlen(sv) : 0);
|
|
1123
1142
|
free(sv);
|
|
1124
|
-
if (tn)
|
|
1143
|
+
if (tn) {
|
|
1144
|
+
xpath_nodeset_add(one, tn);
|
|
1145
|
+
one->owns_synthetic_text = 1;
|
|
1146
|
+
}
|
|
1125
1147
|
}
|
|
1126
|
-
/* synth members above are var-owned */
|
|
1127
|
-
one->owns_synthetic_text = 1;
|
|
1128
1148
|
}
|
|
1129
1149
|
xpath_variable_set_nodeset(var, one);
|
|
1130
1150
|
if (pos_var) {
|
|
@@ -1900,9 +1920,12 @@ struct leptris_xpath_result* evaluate_operator(XPathContext* ctx,
|
|
|
1900
1920
|
pname[pn] = 0;
|
|
1901
1921
|
XPathNodeSet* one = xpath_nodeset_new();
|
|
1902
1922
|
if (one) {
|
|
1903
|
-
/* set_remove frees the nodeset
|
|
1904
|
-
* the
|
|
1905
|
-
|
|
1923
|
+
/* set_remove frees the nodeset: the flag rides ONLY
|
|
1924
|
+
* the synth-append branches — carrier-node members
|
|
1925
|
+
* are document references and must never dispose
|
|
1926
|
+
* (a whole-set flag over mixed members freed a
|
|
1927
|
+
* document text node in the nightly, SOTA C1
|
|
1928
|
+
* 44085294402). */
|
|
1906
1929
|
if (ai < (size_t)ast->child_count) {
|
|
1907
1930
|
struct leptris_xpath_result* ar =
|
|
1908
1931
|
evaluate_expr(ctx, ast->children[ai]);
|
|
@@ -1928,7 +1951,10 @@ struct leptris_xpath_result* evaluate_operator(XPathContext* ctx,
|
|
|
1928
1951
|
} else {
|
|
1929
1952
|
XPathTextNode* tn = synth_text(
|
|
1930
1953
|
mem[j], strlen(mem[j]));
|
|
1931
|
-
if (tn)
|
|
1954
|
+
if (tn) {
|
|
1955
|
+
xpath_nodeset_add(one, tn);
|
|
1956
|
+
one->owns_synthetic_text = 1;
|
|
1957
|
+
}
|
|
1932
1958
|
}
|
|
1933
1959
|
free(mem[j]);
|
|
1934
1960
|
}
|
|
@@ -1947,7 +1973,10 @@ struct leptris_xpath_result* evaluate_operator(XPathContext* ctx,
|
|
|
1947
1973
|
synth_text(sv ? sv : "",
|
|
1948
1974
|
sv ? strlen(sv) : 0);
|
|
1949
1975
|
free(sv);
|
|
1950
|
-
if (tn)
|
|
1976
|
+
if (tn) {
|
|
1977
|
+
xpath_nodeset_add(one, tn);
|
|
1978
|
+
one->owns_synthetic_text = 1;
|
|
1979
|
+
}
|
|
1951
1980
|
sv = NULL;
|
|
1952
1981
|
}
|
|
1953
1982
|
if (sv) free(sv);
|
|
@@ -2090,26 +2119,39 @@ struct leptris_xpath_result* evaluate_operator(XPathContext* ctx,
|
|
|
2090
2119
|
}
|
|
2091
2120
|
XPathNodeSet* one = xpath_nodeset_new();
|
|
2092
2121
|
if (one) {
|
|
2093
|
-
one->owns_synthetic_text = 1;
|
|
2094
2122
|
if (v->type == XPATH_RESULT_NODESET &&
|
|
2095
2123
|
v->value.nodeset_value &&
|
|
2096
2124
|
v->value.nodeset_value->count > 0) {
|
|
2097
2125
|
/* Node operands bind AS NODES — the arm
|
|
2098
2126
|
* body steps axes on them
|
|
2099
2127
|
* (fold-left-016: $a/text()); a
|
|
2100
|
-
* string-value synth has no children.
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2128
|
+
* string-value synth has no children.
|
|
2129
|
+
* Members v OWNS transfer here (v is
|
|
2130
|
+
* freed below; the transfer keeps `one`
|
|
2131
|
+
* the sole owner). Document members ride
|
|
2132
|
+
* with no flag — a whole-set flag over
|
|
2133
|
+
* mixed members made the case-arm dispose
|
|
2134
|
+
* a document text node (SOTA C1, nightly
|
|
2135
|
+
* 44085294402). */
|
|
2136
|
+
XPathNodeSet* bv = v->value.nodeset_value;
|
|
2137
|
+
for (size_t xi = 0; xi < bv->count; xi++)
|
|
2138
|
+
xpath_nodeset_add(one, bv->nodes[xi]);
|
|
2139
|
+
one->owns_attributes |= bv->owns_attributes;
|
|
2140
|
+
one->owns_namespaces |= bv->owns_namespaces;
|
|
2141
|
+
one->owns_synthetic_text |=
|
|
2142
|
+
bv->owns_synthetic_text;
|
|
2143
|
+
bv->owns_attributes = 0;
|
|
2144
|
+
bv->owns_namespaces = 0;
|
|
2145
|
+
bv->owns_synthetic_text = 0;
|
|
2107
2146
|
} else {
|
|
2108
2147
|
const char* bindv =
|
|
2109
2148
|
marked ? marked : (vs_ ? vs_ : "");
|
|
2110
2149
|
XPathTextNode* tn = xpath_synth_text(
|
|
2111
2150
|
bindv, strlen(bindv));
|
|
2112
|
-
if (tn)
|
|
2151
|
+
if (tn) {
|
|
2152
|
+
xpath_nodeset_add(one, tn);
|
|
2153
|
+
one->owns_synthetic_text = 1;
|
|
2154
|
+
}
|
|
2113
2155
|
}
|
|
2114
2156
|
XPathVariable* var = xpath_variable_set_add(
|
|
2115
2157
|
vs, vn, XPATH_VAR_TYPE_NODE_SET);
|
|
@@ -3578,7 +3620,6 @@ struct leptris_xpath_result* evaluate_operator(XPathContext* ctx,
|
|
|
3578
3620
|
if (op == XPATH_OP_SEQUENCE) {
|
|
3579
3621
|
XPathNodeSet* out = xpath_nodeset_new();
|
|
3580
3622
|
if (!out) return NULL;
|
|
3581
|
-
out->owns_synthetic_text = 1;
|
|
3582
3623
|
out->is_sequence = 1;
|
|
3583
3624
|
for (size_t i = 0; i < ast->child_count; i++) {
|
|
3584
3625
|
struct leptris_xpath_result* item =
|
|
@@ -3587,6 +3628,11 @@ struct leptris_xpath_result* evaluate_operator(XPathContext* ctx,
|
|
|
3587
3628
|
if (item->type == XPATH_RESULT_NODESET &&
|
|
3588
3629
|
item->value.nodeset_value) {
|
|
3589
3630
|
XPathNodeSet* is = item->value.nodeset_value;
|
|
3631
|
+
/* The sequence flag asserts a fact about every
|
|
3632
|
+
* member: raw document members ride in with NO flag
|
|
3633
|
+
* (an eager flag here let apply_predicates dispose
|
|
3634
|
+
* document-owned text nodes — SOTA C1, nightly
|
|
3635
|
+
* 44085294402); owned members transfer below. */
|
|
3590
3636
|
for (size_t j = 0; j < is->count; j++)
|
|
3591
3637
|
xpath_nodeset_add(out, is->nodes[j]);
|
|
3592
3638
|
/* #720: an item nodeset may OWN synthetic nodes
|
|
@@ -3643,7 +3689,10 @@ struct leptris_xpath_result* evaluate_operator(XPathContext* ctx,
|
|
|
3643
3689
|
marked[2 + pl] = 0;
|
|
3644
3690
|
XPathTextNode* tn = synth_text(marked, pl + 2);
|
|
3645
3691
|
free(marked);
|
|
3646
|
-
if (tn)
|
|
3692
|
+
if (tn) {
|
|
3693
|
+
xpath_nodeset_add(out, tn);
|
|
3694
|
+
out->owns_synthetic_text = 1;
|
|
3695
|
+
}
|
|
3647
3696
|
}
|
|
3648
3697
|
} else if (item->type == XPATH_RESULT_BOOLEAN) {
|
|
3649
3698
|
/* "\x03B" marks boolean members so EBV
|
|
@@ -3659,7 +3708,10 @@ struct leptris_xpath_result* evaluate_operator(XPathContext* ctx,
|
|
|
3659
3708
|
XPathTextNode* tn =
|
|
3660
3709
|
synth_text(marked, strlen(bp) + 2);
|
|
3661
3710
|
free(marked);
|
|
3662
|
-
if (tn)
|
|
3711
|
+
if (tn) {
|
|
3712
|
+
xpath_nodeset_add(out, tn);
|
|
3713
|
+
out->owns_synthetic_text = 1;
|
|
3714
|
+
}
|
|
3663
3715
|
}
|
|
3664
3716
|
} else {
|
|
3665
3717
|
char fam = (item->type == XPATH_RESULT_STRING &&
|
|
@@ -3678,13 +3730,19 @@ struct leptris_xpath_result* evaluate_operator(XPathContext* ctx,
|
|
|
3678
3730
|
XPathTextNode* tn =
|
|
3679
3731
|
synth_text(marked, pl + 2);
|
|
3680
3732
|
free(marked);
|
|
3681
|
-
if (tn)
|
|
3733
|
+
if (tn) {
|
|
3734
|
+
xpath_nodeset_add(out, tn);
|
|
3735
|
+
out->owns_synthetic_text = 1;
|
|
3736
|
+
}
|
|
3682
3737
|
}
|
|
3683
3738
|
} else {
|
|
3684
3739
|
XPathTextNode* tn =
|
|
3685
3740
|
synth_text(piece ? piece : "",
|
|
3686
3741
|
piece ? strlen(piece) : 0);
|
|
3687
|
-
if (tn)
|
|
3742
|
+
if (tn) {
|
|
3743
|
+
xpath_nodeset_add(out, tn);
|
|
3744
|
+
out->owns_synthetic_text = 1;
|
|
3745
|
+
}
|
|
3688
3746
|
}
|
|
3689
3747
|
}
|
|
3690
3748
|
free(piece);
|
|
@@ -507,6 +507,30 @@ static XPathASTNode* parse_expr(XPathParser* parser) {
|
|
|
507
507
|
XPathASTNode* xpath_parse(XPathParser* parser) {
|
|
508
508
|
if (!parser) return NULL;
|
|
509
509
|
|
|
510
|
+
/* Nesting fence: the parse chain recurses per '(' / '[' — a
|
|
511
|
+
* pathological expression dies on the C stack before any bound.
|
|
512
|
+
* The tokens are already lexed, so one O(n) scan measures the
|
|
513
|
+
* exact nesting depth and fails cleanly past the fence (SOTA C1,
|
|
514
|
+
* nightly 44278536885, crash-94a0fc23: '[[[[...' × thousands). */
|
|
515
|
+
{
|
|
516
|
+
int cur = 0, max = 0;
|
|
517
|
+
for (size_t i = 0; i < parser->token_count; i++) {
|
|
518
|
+
int t = parser->tokens[i].type;
|
|
519
|
+
if (t == TOK_LPAREN || t == TOK_LBRACKET) {
|
|
520
|
+
if (++cur > max) max = cur;
|
|
521
|
+
} else if (t == TOK_RPAREN || t == TOK_RBRACKET) {
|
|
522
|
+
if (cur > 0) cur--;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if (max > 128) {
|
|
526
|
+
snprintf(parser->error_msg, sizeof(parser->error_msg),
|
|
527
|
+
"expression nesting too deep (%d levels)", max);
|
|
528
|
+
leptris_set_error(LEPTRIS_ERROR_XPATH_SYNTAX,
|
|
529
|
+
parser->error_msg);
|
|
530
|
+
return NULL;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
510
534
|
XPathASTNode* ast = parse_expr(parser);
|
|
511
535
|
/* XPath 3.1 top-level sequence: Expr ::= ExprSingle ("," ExprSingle)*.
|
|
512
536
|
* One member parses as itself; a comma list builds the sequence
|
|
@@ -3420,6 +3420,21 @@ static int xslt_bind_param_defaults(XsltExec* ex, const XsltInstr* body,
|
|
|
3420
3420
|
static int xslt_invoke_template(XsltExec* ex, const XsltTemplate* t,
|
|
3421
3421
|
LeptrisElement node,
|
|
3422
3422
|
const XsltInstr* with_params) {
|
|
3423
|
+
/* Recursion fence (SOTA C1, nightly 44278536885): an identity
|
|
3424
|
+
* template whose apply-templates select re-selects the same node
|
|
3425
|
+
* recurses until the OS stack dies. The fence fails the
|
|
3426
|
+
* transform cleanly instead. 100 sits far below the C stack even
|
|
3427
|
+
* under ASan's frame inflation (~60KB/level measured on the
|
|
3428
|
+
* nightly input) while covering every legitimate rule chain —
|
|
3429
|
+
* libxslt dies on the OS stack for the same input. */
|
|
3430
|
+
if (++ex->apply_depth > 100) {
|
|
3431
|
+
snprintf(ex->error, sizeof(ex->error),
|
|
3432
|
+
"template recursion exceeded 100 levels "
|
|
3433
|
+
"(apply-templates/call-template loop)");
|
|
3434
|
+
ex->eval_error = 1;
|
|
3435
|
+
ex->apply_depth--;
|
|
3436
|
+
return -2;
|
|
3437
|
+
}
|
|
3423
3438
|
const XsltTemplate* saved_t = ex->current_template;
|
|
3424
3439
|
ex->current_template = t;
|
|
3425
3440
|
/* §11: with-param expressions evaluate in the CALLER's scope;
|
|
@@ -3480,6 +3495,7 @@ static int xslt_invoke_template(XsltExec* ex, const XsltTemplate* t,
|
|
|
3480
3495
|
ex->current_template = saved_t;
|
|
3481
3496
|
xslt_pop_vars_to(ex, mark);
|
|
3482
3497
|
ex->vars = caller;
|
|
3498
|
+
ex->apply_depth--;
|
|
3483
3499
|
return rc;
|
|
3484
3500
|
}
|
|
3485
3501
|
|
|
@@ -662,6 +662,12 @@ typedef struct xslt_exec {
|
|
|
662
662
|
* resolves candidates against THIS rule's import rank). */
|
|
663
663
|
const XsltTemplate* current_template;
|
|
664
664
|
|
|
665
|
+
/* Recursion fence (SOTA C1, nightly 44278536885): template
|
|
666
|
+
* invocations in flight. apply-templates select="." identity
|
|
667
|
+
* loops recurse unbounded and die on the C stack — the engine
|
|
668
|
+
* fails the transform cleanly past the fence instead. */
|
|
669
|
+
int apply_depth;
|
|
670
|
+
|
|
665
671
|
/* §4: the in-scope ns bindings of the instruction in flight —
|
|
666
672
|
* installed by the walker, consumed by xslt_eval. */
|
|
667
673
|
LeptrisXPathNsSet current_ns;
|
|
@@ -98,3 +98,12 @@ Add the file to `corpus/`, then add its name + XPath to the `DOCS` /
|
|
|
98
98
|
`XPATHS` tables in **all three** runners (order matters: fixed corpus
|
|
99
99
|
order, no sorting), re-run all three, and update the verified-output
|
|
100
100
|
block above plus this README's tables.
|
|
101
|
+
|
|
102
|
+
## Where the pins come from
|
|
103
|
+
|
|
104
|
+
The gate reads its four binding pins from the LATEST RELEASE's
|
|
105
|
+
`build-manifest.json` (`bindings` section — recorded live from the
|
|
106
|
+
registries by the release workflow, Gate C3). Releases predating
|
|
107
|
+
schema/2 fall back to the hardcoded `FALLBACK_*` train in the
|
|
108
|
+
workflow header; the diffpins branches only need to touch those
|
|
109
|
+
fallbacks, never the install steps.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<?xmlstylesheet ymlversion="1.0"><xsl:template mat<xslch=":s
|
|
Binary file
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Grammar-aware HTML seed generator (SOTA C1 #2051): documents that
|
|
3
|
+
anchor the tokenizer's STATE SPACE — foreign content (SVG/MATH with
|
|
4
|
+
integration points), CDATA-ish surprises, self-closing tags, weird
|
|
5
|
+
names, implied end tags, attributes with odd spellings, comments/
|
|
6
|
+
doctypes in odd positions. HTML parsing is error-recovery by design;
|
|
7
|
+
the generator exercises the recovery paths from INSIDE the grammar
|
|
8
|
+
rather than at byte-flip distance. Deterministic under --seed.
|
|
9
|
+
|
|
10
|
+
Usage: gen_html_seeds.py OUTDIR [--seed N] [--count N]
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import os
|
|
15
|
+
import random
|
|
16
|
+
|
|
17
|
+
BLOCK = ["div", "p", "section", "li", "td", "tr", "table"]
|
|
18
|
+
FOREIGN = ["svg", "math"]
|
|
19
|
+
SVG_KIDS = ["path", "circle", "g", "foreignObject", "desc", "title",
|
|
20
|
+
"text", "clipPath", "use"]
|
|
21
|
+
MATH_KIDS = ["mi", "mo", "mn", "mrow", "msup", "annotation-xml"]
|
|
22
|
+
WEIRD_TAGS = ["a<b", "foo.bar", "x:y", "font-face-uri", "set"]
|
|
23
|
+
TEXTS = ["hello", "42", "a < b", "<notatag", "&amp", " "]
|
|
24
|
+
ATTR_SPELLINGS = ['class="x"', "id=noquotes", "data-x='y'",
|
|
25
|
+
"DATA-UPPER=1", 'disabled', '=""',
|
|
26
|
+
'style="color:red"']
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def attrs(rng):
|
|
30
|
+
return (" " + " ".join(rng.sample(
|
|
31
|
+
ATTR_SPELLINGS, rng.randint(0, 3)))) if rng.random() < 0.8 else ""
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def html(rng, depth):
|
|
35
|
+
out = []
|
|
36
|
+
for _ in range(rng.randint(1, 4)):
|
|
37
|
+
r = rng.random()
|
|
38
|
+
if r < 0.30 and depth > 0:
|
|
39
|
+
t = rng.choice(BLOCK)
|
|
40
|
+
out.append(f"<{t}{attrs(rng)}>{html(rng, depth - 1)}</{t}>")
|
|
41
|
+
elif r < 0.50:
|
|
42
|
+
f = rng.choice(FOREIGN)
|
|
43
|
+
kids = rng.choice(SVG_KIDS) if f == "svg" else rng.choice(MATH_KIDS)
|
|
44
|
+
inner = "".join(
|
|
45
|
+
f"<{kids}{attrs(rng)}{rng.choice(['', ' />', ' /'])}>"
|
|
46
|
+
for _ in range(rng.randint(1, 3)))
|
|
47
|
+
tail = rng.choice(["", "<![CDATA[x]]>", "</p>"])
|
|
48
|
+
out.append(f"<{f}{attrs(rng)}>{inner}{tail}</{f}>")
|
|
49
|
+
elif r < 0.58:
|
|
50
|
+
out.append(rng.choice(TEXTS))
|
|
51
|
+
elif r < 0.64:
|
|
52
|
+
out.append(f"<!-- comment {rng.randint(0, 9)} -->")
|
|
53
|
+
elif r < 0.70:
|
|
54
|
+
out.append(f"<{rng.choice(WEIRD_TAGS)}{attrs(rng)}>")
|
|
55
|
+
elif r < 0.76:
|
|
56
|
+
out.append(rng.choice(["<br>", "<hr/>", "<img src=x>",
|
|
57
|
+
"<input value=?>"]))
|
|
58
|
+
elif r < 0.82:
|
|
59
|
+
out.append(rng.choice(["<p>", "</p>", "<li>", "</li>"]))
|
|
60
|
+
elif r < 0.88:
|
|
61
|
+
out.append(f"<script{attrs(rng)}>if (a<b) x();</script>")
|
|
62
|
+
elif r < 0.94:
|
|
63
|
+
out.append(f"<style>p {{ color: red }}</style>")
|
|
64
|
+
else:
|
|
65
|
+
out.append("<template><td><a href=#>t</td></template>")
|
|
66
|
+
return "".join(out)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def gen_doc(rng):
|
|
70
|
+
parts = []
|
|
71
|
+
if rng.random() < 0.7:
|
|
72
|
+
parts.append(rng.choice([
|
|
73
|
+
"<!DOCTYPE html>", "<!doctype html>",
|
|
74
|
+
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\">",
|
|
75
|
+
]))
|
|
76
|
+
parts.append("<html>")
|
|
77
|
+
if rng.random() < 0.6:
|
|
78
|
+
parts.append(f"<head><meta charset=utf-8><title>t</title></head>")
|
|
79
|
+
parts.append(f"<body>{html(rng, rng.randint(1, 5))}</body>")
|
|
80
|
+
parts.append("</html>")
|
|
81
|
+
return "".join(parts) + "\n"
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def main():
|
|
85
|
+
ap = argparse.ArgumentParser()
|
|
86
|
+
ap.add_argument("outdir")
|
|
87
|
+
ap.add_argument("--seed", type=int, default=0)
|
|
88
|
+
ap.add_argument("--count", type=int, default=100)
|
|
89
|
+
args = ap.parse_args()
|
|
90
|
+
|
|
91
|
+
os.makedirs(args.outdir, exist_ok=True)
|
|
92
|
+
rng = random.Random(args.seed)
|
|
93
|
+
for i in range(args.count):
|
|
94
|
+
with open(os.path.join(args.outdir, f"gen{i:04d}.html"), "w",
|
|
95
|
+
encoding="utf-8") as f:
|
|
96
|
+
f.write(gen_doc(rng))
|
|
97
|
+
print(f"wrote {args.count} seeds to {args.outdir}")
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
if __name__ == "__main__":
|
|
101
|
+
main()
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Grammar-aware XML seed generator (SOTA C1 #2051): documents whose
|
|
3
|
+
SHAPE anchors libFuzzer's parse-family coverage — nesting depth,
|
|
4
|
+
mixed content, CDATA, entity references (predefined and DTD-declared),
|
|
5
|
+
namespaces (default, prefixed, un-declaration), PIs, comments,
|
|
6
|
+
attribute storms. Pure byte-flip mutation reaches these structures
|
|
7
|
+
slowly; the generator composes them validly (well-formed: bound
|
|
8
|
+
prefixes, no duplicate attributes, DTD-backed entity refs) so the
|
|
9
|
+
parse fuzz leg starts from inside the grammar. Deterministic under
|
|
10
|
+
--seed.
|
|
11
|
+
|
|
12
|
+
Usage: gen_xml_seeds.py OUTDIR [--seed N] [--count N]
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import argparse
|
|
16
|
+
import os
|
|
17
|
+
import random
|
|
18
|
+
|
|
19
|
+
NAMES = ["r", "item", "entry", "node", "leaf", "span", "rec", "a", "b"]
|
|
20
|
+
ATTR_NAMES = ["id", "kind", "status", "sku", "lang", "type"]
|
|
21
|
+
NS = ["http://example.com/ns1", "http://example.com/ns2", "urn:leptris:test"]
|
|
22
|
+
PFX = ["n1", "n2", "t"]
|
|
23
|
+
TEXTS = ["hello", "42", "a & b", "line1\nline2", " spaced ",
|
|
24
|
+
"café", "✓"]
|
|
25
|
+
PREDEFINED = ["&", "<", ">", """, "'"]
|
|
26
|
+
DTD_ENTITIES = ["nbsp", "mdash", "ce"]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def gen_attrs(rng, used, pfx):
|
|
30
|
+
out = []
|
|
31
|
+
pool = [a for a in ATTR_NAMES if a not in used]
|
|
32
|
+
rng.shuffle(pool)
|
|
33
|
+
for name in pool[: rng.randint(0, 3)]:
|
|
34
|
+
val = rng.choice(['"1"', "'x y'", '"a<b"', f'"{rng.choice(TEXTS)}"'])
|
|
35
|
+
used.add(name)
|
|
36
|
+
out.append(f"{name}={val}")
|
|
37
|
+
if pfx and rng.random() < 0.5:
|
|
38
|
+
name = f"{pfx}.attr"
|
|
39
|
+
if name not in used:
|
|
40
|
+
used.add(name)
|
|
41
|
+
out.append(f'{pfx}:attr="{rng.randint(0, 99)}"')
|
|
42
|
+
return (" " + " ".join(out)) if out else ""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def element(rng, depth, st, root_extra=""):
|
|
46
|
+
if depth <= 0:
|
|
47
|
+
name = f"{st['pfx']}:leaf" if (st["pfx"] and rng.random() < 0.5) else "leaf"
|
|
48
|
+
used = set()
|
|
49
|
+
kind = rng.random()
|
|
50
|
+
if kind < 0.2:
|
|
51
|
+
return f"<{name}{gen_attrs(rng, used, st['pfx'])}/>"
|
|
52
|
+
if kind < 0.4:
|
|
53
|
+
return (f"<{name}{gen_attrs(rng, used, st['pfx'])}>"
|
|
54
|
+
f"<![CDATA[{rng.choice(['x < y', 'traps & gone', 'plain'])}]]>"
|
|
55
|
+
f"</{name}>")
|
|
56
|
+
return f"<{name}{gen_attrs(rng, used, st['pfx'])}>{rng.choice(TEXTS)}</{name}>"
|
|
57
|
+
|
|
58
|
+
prefixed = st["pfx"] and rng.random() < 0.4
|
|
59
|
+
name = f"{st['pfx']}:{rng.choice(NAMES)}" if prefixed else rng.choice(NAMES)
|
|
60
|
+
used = set()
|
|
61
|
+
extra = None if root_extra else ""
|
|
62
|
+
if extra is None:
|
|
63
|
+
pass # the root's xmlns choices live in root_extra
|
|
64
|
+
elif rng.random() < 0.3:
|
|
65
|
+
extra = f' xmlns="{rng.choice(NS)}"'
|
|
66
|
+
elif rng.random() < 0.2:
|
|
67
|
+
extra = ' xmlns=""'
|
|
68
|
+
|
|
69
|
+
children = []
|
|
70
|
+
for _ in range(rng.randint(1, 4)):
|
|
71
|
+
kind = rng.random()
|
|
72
|
+
if kind < 0.55:
|
|
73
|
+
children.append(element(rng, depth - 1, st))
|
|
74
|
+
elif kind < 0.65:
|
|
75
|
+
children.append(f"<!-- comment {rng.randint(0, 99)} -->")
|
|
76
|
+
elif kind < 0.72:
|
|
77
|
+
children.append(f"<?pi{rng.randint(0, 9)} data?>")
|
|
78
|
+
elif kind < 0.82:
|
|
79
|
+
if st["has_dtd"] and rng.random() < 0.5:
|
|
80
|
+
ent = f"&{rng.choice(DTD_ENTITIES)};"
|
|
81
|
+
else:
|
|
82
|
+
ent = rng.choice(PREDEFINED)
|
|
83
|
+
children.append(f"t{ent}t")
|
|
84
|
+
else:
|
|
85
|
+
children.append(rng.choice(TEXTS))
|
|
86
|
+
body = "".join(children)
|
|
87
|
+
open_attrs = (gen_attrs(rng, used, st["pfx"]) + (extra or "")
|
|
88
|
+
+ root_extra)
|
|
89
|
+
if rng.random() < 0.15:
|
|
90
|
+
return f"<{name}{open_attrs}/>"
|
|
91
|
+
return f"<{name}{open_attrs}>{body}</{name}>"
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def gen_doc(rng):
|
|
95
|
+
has_dtd = rng.random() < 0.4
|
|
96
|
+
dtd = ""
|
|
97
|
+
if has_dtd:
|
|
98
|
+
ents = "".join(
|
|
99
|
+
f'<!ENTITY {e} "{rng.choice([" ", "—", "custom"])}">'
|
|
100
|
+
for e in DTD_ENTITIES)
|
|
101
|
+
dtd = f"<!DOCTYPE r [<!ELEMENT r ANY>{ents}]>\n"
|
|
102
|
+
pfx = rng.choice(PFX) if rng.random() < 0.5 else None
|
|
103
|
+
st = {"pfx": pfx, "has_dtd": has_dtd}
|
|
104
|
+
root_extra = f' xmlns:{pfx}="{rng.choice(NS)}"' if pfx else ""
|
|
105
|
+
if rng.random() < 0.4:
|
|
106
|
+
root_extra += f' xmlns="{rng.choice(NS)}"'
|
|
107
|
+
decl = ('<?xml version="1.0" encoding="UTF-8"?>\n'
|
|
108
|
+
if rng.random() < 0.8 else "")
|
|
109
|
+
return (decl + dtd
|
|
110
|
+
+ element(rng, rng.randint(1, 6), st,
|
|
111
|
+
root_extra=root_extra) + "\n")
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def main():
|
|
115
|
+
ap = argparse.ArgumentParser()
|
|
116
|
+
ap.add_argument("outdir")
|
|
117
|
+
ap.add_argument("--seed", type=int, default=0)
|
|
118
|
+
ap.add_argument("--count", type=int, default=100)
|
|
119
|
+
args = ap.parse_args()
|
|
120
|
+
|
|
121
|
+
os.makedirs(args.outdir, exist_ok=True)
|
|
122
|
+
rng = random.Random(args.seed)
|
|
123
|
+
for i in range(args.count):
|
|
124
|
+
doc = gen_doc(rng)
|
|
125
|
+
with open(os.path.join(args.outdir, f"gen{i:04d}.xml"), "w",
|
|
126
|
+
encoding="utf-8") as f:
|
|
127
|
+
f.write(doc)
|
|
128
|
+
print(f"wrote {args.count} seeds to {args.outdir}")
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
if __name__ == "__main__":
|
|
132
|
+
main()
|