leptris 1.9.427.0-arm-linux → 1.9.428.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.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/lib/leptris/version.rb +1 -1
  4. data/lib/libleptris.so +0 -0
  5. data/vendor-src/README.md +1 -1
  6. data/vendor-src/libleptris/CHANGELOG.md +19 -0
  7. data/vendor-src/libleptris/CMakeLists.txt +1 -1
  8. data/vendor-src/libleptris/scripts/verify_manifest.py +11 -3
  9. data/vendor-src/libleptris/src/leptris/encoding/wrapper.c +13 -3
  10. data/vendor-src/libleptris/src/leptris/leptris_internal.h +19 -0
  11. data/vendor-src/libleptris/src/leptris/rng/parse.c +21 -5
  12. data/vendor-src/libleptris/src/leptris/xpath/evaluator.c +59 -19
  13. data/vendor-src/libleptris/src/leptris/xpath/evaluator_operators.c +83 -25
  14. data/vendor-src/libleptris/src/leptris/xpath/parser.c +24 -0
  15. data/vendor-src/libleptris/src/leptris/xslt/xslt_exec.c +16 -0
  16. data/vendor-src/libleptris/src/leptris/xslt/xslt_internal.h +6 -0
  17. data/vendor-src/libleptris/test/differential/README.md +9 -0
  18. data/vendor-src/libleptris/test/differential/package.json +1 -1
  19. data/vendor-src/libleptris/test/differential/rs-runner/Cargo.toml +1 -1
  20. data/vendor-src/libleptris/test/fuzz/corpus/encoding_decl_strstr_hbo.bin +1 -0
  21. data/vendor-src/libleptris/test/fuzz/corpus/xpath_bracket_nesting_stack_overflow.bin +0 -0
  22. data/vendor-src/libleptris/test/fuzz/corpus/xslt_apply_identity_recursion.bin +0 -0
  23. data/vendor-src/libleptris/test/fuzz/corpus/xslt_mixed_set_dispose_uaf.bin +0 -0
  24. data/vendor-src/libleptris/test/fuzz/generators/gen_xml_seeds.py +132 -0
  25. data/vendor-src/libleptris/test/rng/test_rng.cpp +118 -0
  26. data/vendor-src/libleptris/test/xpath/test_xpath.cpp +77 -0
  27. data/vendor-src/libleptris/test/xpath/test_xslt.cpp +80 -0
  28. data/vendor-src/libleptris/vcpkg.json +1 -1
  29. metadata +6 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97e62117bea69c65459eb62388f938d9ce7807d3bfbf6fd0fa806b5a85d541d6
4
- data.tar.gz: 84dee1e74e76b3ab5e0abcae620e57b71f5fa73f7e26be7abd9c23b35e6d37a2
3
+ metadata.gz: c94db1bb2659005dc214b578004962aee4af03781f3eb5eb45c8f8f115a75a85
4
+ data.tar.gz: 97f8259d1f48825905082488be52960c4aabbe579846429043063833fd6ba591
5
5
  SHA512:
6
- metadata.gz: e652f22bff3c8e11f98e0cabc70423508fa488185de1b4423ca43de44e0a6518ead1172ae50b32ecdaad966e73f016e1cca1d3f723085e05d0585cea0b45d2f5
7
- data.tar.gz: 2bb2f2ff2302a355608468535e8067ce37b929251df2663118e4c795dad4f0aaea37b0d704111ac9a578bccb9174dbf2acd046fe143d320fc4f70b405b110094
6
+ metadata.gz: 82429af640ba53b13f601efd21f242df100cbb14df22589a9f8a17e9f876bd04139fadf2e94f2ad522d30606e37dd135332d9cf3da4c6a25e23ec396a501ace9
7
+ data.tar.gz: c952e98d38d8917f23e54cfb37e9d0d12cd1f4bb6322c3f81e1f6fcda83f2e00eeb309a4c0798d5d19951c6d637f72703247d5dce1ad82c09c2c531ef20526e2
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ RSpec::Core::RakeTask.new(:spec)
8
8
  # Pin for `rake compile` and the platform-gem builds. Keep in lockstep
9
9
  # with .github/workflows/build.yml (which calls `rake compile`) and the
10
10
  # CHANGELOG when libleptris releases.
11
- LIBLEPTRIS_VERSION = "1.9.427"
11
+ LIBLEPTRIS_VERSION = "1.9.428"
12
12
 
13
13
  # THE SSOT for the per-minor native bundle list (ruby#645): one line,
14
14
  # space-separated, consumed by the Rakefile, the per-minor builder's
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Leptris
4
- VERSION = "1.9.427.0"
4
+ VERSION = "1.9.428.0"
5
5
  end
data/lib/libleptris.so CHANGED
Binary file
data/vendor-src/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Sources vendored in this gem (recompile rights; the ruby
2
2
  variant builds them at install via extconf.rb):
3
3
 
4
- - libleptris v1.9.427
4
+ - libleptris v1.9.428
5
5
  - utf8proc v2.11.0
6
6
 
7
7
  Rebuild by hand:
@@ -1,5 +1,24 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.9.428] - 2026-11-18
4
+
5
+ ### Fixed
6
+
7
+ - RELAX NG: a `combine="choice"`/`combine="interleave"` merge wraps each merged body in an implicit group (Jing §4.10) — the branch is the body's whole sibling chain, not its first element. Multi-element bodies under a combined define no longer reject everything after the first element (the openmath3.rng OMBIND shape — OM3 documents rejected OMBVAR/OMA after the head OMS) (leptris#2088, leptris#2089).
8
+
9
+ ### Memory safety (SOTA C1, fuzz-lane findings 8–11)
10
+
11
+ - XPath synthetic nodes (attribute/namespace/text) are shared by value across nodesets, sequences, and variable bindings; no set owns them exclusively. Disposing one no longer frees the struct under its other holders: the node parks (a defined-dead sentinel + thread-local graveyard drained at cleanup) instead (nightly 44085294402).
12
+ - Five binding producers (simple-map, sequence, for loop-var, HOF params, switch cases) flagged result sets eagerly and appended raw document nodes — a predicate drop then disposed a document-owned text node. Ownership flags now assert facts and transfer with owned members (leptris#2083).
13
+ - The encoding-declaration scan is bounded: the buffer is not NUL-terminated on every caller and the unbounded `strstr` read past the end.
14
+ - Two clean-error recursion fences: template application caps at 100 levels (an `apply-templates select="."` identity loop previously died on the OS stack), and the XPath parser rejects bracket nesting past 128 with a syntax error instead of exhausting the C stack (nightly 44278536885).
15
+
16
+ ### Packaging
17
+
18
+ - Every release now carries `build-manifest.json` (per-platform toolchain identities, artifact hashes, and the binding versions riding the release), generated by the release workflow; the byte-identity smoke is green after pinning the compiler's path-derived symbol seed; the differential gate reads its pins from the release manifest (leptris#2085, leptris#2086).
19
+
20
+
21
+
3
22
  ## [1.9.427] - 2026-11-18
4
23
 
5
24
  ### Fixed
@@ -3,7 +3,7 @@
3
3
  cmake_minimum_required(VERSION 3.20)
4
4
 
5
5
  project(leptris
6
- VERSION 1.9.427
6
+ VERSION 1.9.428
7
7
  DESCRIPTION "Fast XML parser and XPath evaluator in pure C"
8
8
  LANGUAGES C CXX
9
9
  )
@@ -25,13 +25,21 @@ matched a local file byte-for-byte; 1 = at least one artifact is missing
25
25
  or mismatched. A local file with no manifest entry is a warning, not a
26
26
  failure (extra build outputs are allowed).
27
27
 
28
- Manifest schema ("leptris.build-manifest/1", as produced by
28
+ Manifest schema ("leptris.build-manifest/2", as produced by
29
29
  .github/workflows/build-manifests.yml):
30
30
 
31
31
  {
32
- "schema": "leptris.build-manifest/1",
32
+ "schema": "leptris.build-manifest/2",
33
33
  "tag": "v1.9.367", // release tag built
34
34
  "generated_at_utc": "2026-10-21T00:00:00Z",
35
+ "bindings": { // schema/2 (A6/C3): the
36
+ "rubygems": "1.9.427.0", // published binding
37
+ "pypi": "1.9.427.0", // versions riding this
38
+ "npm": "0.1.62", // engine release, live
39
+ "crates_io": "1.9.0", // from the registries;
40
+ // differential.yml reads
41
+ // these as its pins
42
+ },
35
43
  "platforms": {
36
44
  "<platform>": { // key: matrix leg name, e.g. linux-amd64
37
45
  "leg": "native", // native | amalgamated
@@ -63,7 +71,7 @@ ARTIFACT_RE = re.compile(
63
71
  r"^(libleptris\.(a|dll|lib)|libleptris\.so(\.[0-9.]+)?"
64
72
  r"|libleptris\.[0-9.]+\.dylib|leptris\.(lib|dll))$")
65
73
 
66
- SCHEMA = "leptris.build-manifest/1"
74
+ SCHEMA = "leptris.build-manifest/2"
67
75
 
68
76
 
69
77
  def sha256_of(path):
@@ -36,9 +36,19 @@ char* leptris_encoding_parse_declaration(const char* xml, size_t len) {
36
36
  return NULL;
37
37
  }
38
38
 
39
- /* Find encoding=" */
40
- const char* encoding_start = strstr(xml, "encoding");
41
- if (!encoding_start || encoding_start - xml > (long)len) {
39
+ /* Find encoding= — BOUNDED: the buffer is NOT NUL-terminated on
40
+ * every caller (the fuzz harness passes exact-size buffers; the
41
+ * unbounded strstr read past the end — SOTA C1 finding 9,
42
+ * fx-art-crash-653f55991b38). */
43
+ const char* limit = xml + len;
44
+ const char* encoding_start = NULL;
45
+ for (const char* p = xml; p + 8 <= limit; p++) {
46
+ if (memcmp(p, "encoding", 8) == 0) {
47
+ encoding_start = p;
48
+ break;
49
+ }
50
+ }
51
+ if (!encoding_start) {
42
52
  return NULL;
43
53
  }
44
54
 
@@ -551,6 +551,20 @@ typedef struct xpath_text_node {
551
551
  struct leptris_element* owner; /* Parent element */
552
552
  } XPathTextNode;
553
553
 
554
+ /* Disposed-synthetic parking (SOTA C1, nightly 44085294402): the
555
+ * XPath-side heap nodes (LeptrisAttributeNode / LeptrisNamespaceNode
556
+ * / XPathTextNode) are SHARED by value across nodesets, sequences and
557
+ * variable bindings — no single set owns them exclusively, so a
558
+ * dispose by one holder must not free the struct (or its payload)
559
+ * out from under the others. xpath_nodeset_dispose_node therefore
560
+ * PARKS: the type byte moves to the sentinel below and the struct
561
+ * joins a thread-local graveyard (drained by
562
+ * leptris_xpath_drain_thread_caches at thread exit). Late readers see
563
+ * a defined dead node and defined-dead content instead of freed
564
+ * memory — the same contract as the XPATH_RESULT_CACHED result
565
+ * parking. */
566
+ #define LEPTRIS_NODE_XPATH_PARKED ((LeptrisNodeType)127)
567
+
554
568
  /* XPath node union - type-safe wrapper for all XPath node types */
555
569
  typedef union xpath_node {
556
570
  LeptrisNodeType type; /* First field for type checking */
@@ -673,6 +687,11 @@ typedef struct xpath_parser {
673
687
  size_t token_count;
674
688
  size_t token_pos;
675
689
  char error_msg[256];
690
+ int depth; /* Expression nesting fence — the
691
+ * parse_* chain recurses per '(' '['
692
+ * '!' and dies on the C stack past
693
+ * the fence (SOTA C1, nightly
694
+ * 44278536885 family). */
676
695
  } XPathParser;
677
696
 
678
697
  /* XPath nodeset - Holds typed node pointers (elements or attributes).
@@ -363,10 +363,20 @@ static int add_define(RngGrammar* g, char* name, char* combine,
363
363
  RngPattern* wrap =
364
364
  pat_new(strcmp(d->combine, "interleave") == 0 ? RNG_INTERLEAVE
365
365
  : RNG_CHOICE);
366
- pat_append(wrap, d->body);
367
- pat_append(wrap, body->first_child);
366
+ /* Each merged body is an IMPLICIT GROUP (Jing §4.10): the branch
367
+ * is the body's whole sibling chain, not its first element. A
368
+ * bare chain inside the combinator made the validator treat the
369
+ * body's 2nd..nth elements as further alternatives of the
370
+ * choice — <a/><b/> consumed a as the entire first branch and
371
+ * stranded b (openmath3 OMBIND, #2088). */
372
+ RngPattern* left = pat_new(RNG_GROUP);
373
+ pat_append(left, d->body);
374
+ RngPattern* right = pat_new(RNG_GROUP);
375
+ pat_append(right, body->first_child);
368
376
  body->first_child = NULL;
369
377
  rng_pattern_free(body);
378
+ pat_append(wrap, left);
379
+ pat_append(wrap, right);
370
380
  rng_flatten_combinator(wrap);
371
381
  d->body = wrap;
372
382
  return 1;
@@ -511,15 +521,21 @@ static int handle_include(RngGrammar* g, LeptrisElement inc,
511
521
  /* The WRAPPER stays as the define's body — same shape
512
522
  * add_define produces — the combinator node is what
513
523
  * the validator walks; unwrapping leaves bare
514
- * siblings with no interleave/choice between them. */
524
+ * siblings with no interleave/choice between them.
525
+ * Each branch wraps in GROUP (#2088, Jing §4.10): the
526
+ * branch is the body's whole sibling chain. */
515
527
  RngPattern* wrap =
516
528
  pat_new(strcmp(ncombine, "interleave") == 0
517
529
  ? RNG_INTERLEAVE
518
530
  : RNG_CHOICE);
519
- pat_append(wrap, d->body);
520
- pat_append(wrap, body->first_child);
531
+ RngPattern* left = pat_new(RNG_GROUP);
532
+ pat_append(left, d->body);
533
+ RngPattern* right = pat_new(RNG_GROUP);
534
+ pat_append(right, body->first_child);
521
535
  body->first_child = NULL;
522
536
  rng_pattern_free(body);
537
+ pat_append(wrap, left);
538
+ pat_append(wrap, right);
523
539
  rng_flatten_combinator(wrap);
524
540
  free(d->combine);
525
541
  d->combine = ncombine;
@@ -509,6 +509,8 @@ static LEPTRIS_THREAD_LOCAL struct {
509
509
  size_t nodeset_count;
510
510
  struct leptris_xpath_result* result_head;
511
511
  size_t result_count;
512
+ void* synth_parked_head;
513
+ size_t synth_parked_count;
512
514
  } g_xpath_tls;
513
515
 
514
516
 
@@ -519,6 +521,15 @@ static LEPTRIS_THREAD_LOCAL struct {
519
521
  * to the struct). */
520
522
  #define XPATH_RESULT_FREE_LIST_CAP 32
521
523
 
524
+ /* One parked synthetic node: the node keeps its payload readable
525
+ * (defined-dead), the wrapper remembers the original kind for the
526
+ * drain. */
527
+ typedef struct ParkedSynth {
528
+ struct ParkedSynth* next;
529
+ void* node;
530
+ LeptrisNodeType kind;
531
+ } ParkedSynth;
532
+
522
533
  XPathNodeSet* xpath_nodeset_new(void) {
523
534
  return xpath_nodeset_new_with_capacity(XPATH_NODESET_INLINE_CAPACITY);
524
535
  }
@@ -541,6 +552,31 @@ void leptris_xpath_drain_thread_caches(void) {
541
552
  g_xpath_tls.result_head = next;
542
553
  }
543
554
  g_xpath_tls.result_count = 0;
555
+ /* The parked synthetic nodes (LEPTRIS_NODE_XPATH_PARKED): the
556
+ * thread is exiting — no consumer can still reach them. */
557
+ while (g_xpath_tls.synth_parked_head) {
558
+ ParkedSynth* p = (ParkedSynth*)g_xpath_tls.synth_parked_head;
559
+ g_xpath_tls.synth_parked_head = p->next;
560
+ if (p->kind == LEPTRIS_NODE_ATTRIBUTE) {
561
+ LeptrisAttributeNode* attr = (LeptrisAttributeNode*)p->node;
562
+ LEPTRIS_FREE(attr->name);
563
+ LEPTRIS_FREE(attr->value);
564
+ LEPTRIS_FREE(attr->namespace_uri);
565
+ LEPTRIS_FREE(attr);
566
+ } else if (p->kind == LEPTRIS_NODE_NAMESPACE) {
567
+ LeptrisNamespaceNode* ns = (LeptrisNamespaceNode*)p->node;
568
+ LEPTRIS_FREE(ns->prefix);
569
+ LEPTRIS_FREE(ns->uri);
570
+ LEPTRIS_FREE(ns);
571
+ } else {
572
+ XPathTextNode* t = (XPathTextNode*)p->node;
573
+ LEPTRIS_FREE(t->content);
574
+ LEPTRIS_FREE(t);
575
+ }
576
+ LEPTRIS_FREE(p);
577
+ g_xpath_tls.synth_parked_count--;
578
+ }
579
+ g_xpath_tls.synth_parked_count = 0;
544
580
  }
545
581
 
546
582
  XPathNodeSet* xpath_nodeset_new_with_capacity(size_t capacity) {
@@ -595,27 +631,31 @@ XPathNodeSet* xpath_nodeset_new_with_capacity(size_t capacity) {
595
631
  }
596
632
 
597
633
  /* Dispose ONE heap-owned synthetic node (attribute/namespace/text).
598
- * Shared by xpath_nodeset_free and the in-place predicate filter,
599
- * which drops entries without removing the nodeset's ownership
600
- * (bug: filtered-out namespace nodes leaked — Linux LSan). */
634
+ * Shared by xpath_nodeset_free and the in-place predicate filter.
635
+ *
636
+ * SOTA C1 (nightly 44085294402): these nodes are SHARED by value
637
+ * across nodesets/sequences/bindings — no set owns them exclusively,
638
+ * and a dispose by one holder used to free the struct under the
639
+ * others (the filtered set dropped the node; the flag-losing alias
640
+ * still held it; the axis step read freed memory). The dispose now
641
+ * PARKS (LEPTRIS_NODE_XPATH_PARKED + the thread-local graveyard,
642
+ * drained at thread exit): repeat-dispose and any late read see a
643
+ * defined dead node instead of freed memory. */
601
644
  void xpath_nodeset_dispose_node(void* node) {
602
645
  if (!node) return;
603
- if (XPATH_NODE_TYPE(node) == LEPTRIS_NODE_ATTRIBUTE) {
604
- LeptrisAttributeNode* attr = (LeptrisAttributeNode*)node;
605
- if (attr->name) LEPTRIS_FREE(attr->name);
606
- if (attr->value) LEPTRIS_FREE(attr->value);
607
- if (attr->namespace_uri) LEPTRIS_FREE(attr->namespace_uri);
608
- LEPTRIS_FREE(attr);
609
- } else if (XPATH_NODE_TYPE(node) == LEPTRIS_NODE_NAMESPACE) {
610
- LeptrisNamespaceNode* ns = (LeptrisNamespaceNode*)node;
611
- if (ns->prefix) LEPTRIS_FREE(ns->prefix);
612
- if (ns->uri) LEPTRIS_FREE(ns->uri);
613
- LEPTRIS_FREE(ns);
614
- } else if (XPATH_NODE_TYPE(node) == LEPTRIS_NODE_TEXT) {
615
- XPathTextNode* t = (XPathTextNode*)node;
616
- if (t->content) LEPTRIS_FREE(t->content);
617
- LEPTRIS_FREE(t);
618
- }
646
+ int ty = (int)XPATH_NODE_TYPE(node);
647
+ if (ty == (int)LEPTRIS_NODE_XPATH_PARKED) return;
648
+ if (ty != LEPTRIS_NODE_ATTRIBUTE && ty != LEPTRIS_NODE_NAMESPACE &&
649
+ ty != LEPTRIS_NODE_TEXT)
650
+ return;
651
+ ParkedSynth* p = (ParkedSynth*)LEPTRIS_ALLOC(ParkedSynth);
652
+ if (!p) return; /* un-parked: the node stays alive, leak over UAF */
653
+ p->node = node;
654
+ p->kind = (LeptrisNodeType)ty;
655
+ p->next = (ParkedSynth*)g_xpath_tls.synth_parked_head;
656
+ g_xpath_tls.synth_parked_head = p;
657
+ g_xpath_tls.synth_parked_count++;
658
+ XPATH_NODE_TYPE(node) = LEPTRIS_NODE_XPATH_PARKED;
619
659
  }
620
660
 
621
661
  void xpath_nodeset_free(XPathNodeSet* nodeset) {
@@ -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
- out->owns_synthetic_text = 1;
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) xpath_nodeset_add(out, 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) xpath_nodeset_add(one, 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) xpath_nodeset_add(one, 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 — without this flag
1904
- * the synthetic arg node leaks (48B, Linux LSan). */
1905
- one->owns_synthetic_text = 1;
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) xpath_nodeset_add(one, 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) xpath_nodeset_add(one, 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
- for (size_t xi = 0;
2102
- xi < v->value.nodeset_value->count;
2103
- xi++)
2104
- xpath_nodeset_add(
2105
- one,
2106
- v->value.nodeset_value->nodes[xi]);
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) xpath_nodeset_add(one, 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) xpath_nodeset_add(out, 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) xpath_nodeset_add(out, 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) xpath_nodeset_add(out, 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) xpath_nodeset_add(out, 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.
@@ -4,6 +4,6 @@
4
4
  "type": "module",
5
5
  "description": "Differential corpus runner for the TypeScript/WASM binding. npm install in this directory, then: node run.mjs",
6
6
  "dependencies": {
7
- "leptris": "0.1.59"
7
+ "leptris": "0.1.62"
8
8
  }
9
9
  }
@@ -11,7 +11,7 @@ path = "run.rs"
11
11
  [dependencies]
12
12
  # The published rs binding; the pin rides every train with the other
13
13
  # binding pins (the A6 law). '=' keeps the gate reproducible.
14
- leptris = "=1.7.1"
14
+ leptris = "=1.9.0"
15
15
  sha2 = "0.10"
16
16
 
17
17
  [profile.release]
@@ -0,0 +1 @@
1
+ <?xmlstylesheet ymlversion="1.0"><xsl:template mat<xslch=":s
@@ -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 &amp; b", "line1\nline2", " spaced ",
24
+ "café", "✓"]
25
+ PREDEFINED = ["&amp;", "&lt;", "&gt;", "&quot;", "&apos;"]
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&lt;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(["&#160;", "&#8212;", "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()
@@ -1849,3 +1849,121 @@ TEST(Rng2080Data, HexBinaryLexes) {
1849
1849
  leptris_document_free(d);
1850
1850
  leptris_rng_free(rng);
1851
1851
  }
1852
+
1853
+ /* #2088: a combine="choice" merge wraps BOTH bodies in an implicit
1854
+ * group (Jing §4.10) — the merged combinator's alternatives are
1855
+ * whole bodies, not their first elements. A bare sibling chain as a
1856
+ * branch made match_seq treat the pre-existing body's 2nd..nth
1857
+ * elements as further ALTERNATIVES: <root><a/><b/></root> consumed
1858
+ * a as the whole first alternative and stranded b ("element b not
1859
+ * allowed here") — the openmath3 OMBIND shape. Same rule for
1860
+ * combine="interleave" and for include overrides. */
1861
+ TEST(Rng2088CombineMerge, ChoiceBranchesAreWholeBodies) {
1862
+ const char* schema =
1863
+ "<grammar ns=\"http://ex\" xmlns=\"http://relaxng.org/ns/structure/1.0\">"
1864
+ "<define name=\"content\">"
1865
+ "<element name=\"a\"><empty/></element>"
1866
+ "<element name=\"b\"><empty/></element>"
1867
+ "</define>"
1868
+ "<define name=\"content\" combine=\"choice\">"
1869
+ "<element name=\"c\"><empty/></element>"
1870
+ "</define>"
1871
+ "<start><element name=\"root\"><ref name=\"content\"/></element></start>"
1872
+ "</grammar>";
1873
+ LeptrisRelaxNG rng =
1874
+ leptris_rng_parse(schema, strlen(schema), nullptr);
1875
+ ASSERT_NE(rng, nullptr);
1876
+ LeptrisStatus st = LEPTRIS_OK;
1877
+ struct { const char* doc; int want; const char* why; } cases[] = {
1878
+ {"<root xmlns=\"http://ex\"><a/></root>", 0,
1879
+ "a alone: the base group requires b too"},
1880
+ {"<root xmlns=\"http://ex\"><a/><b/></root>", 1,
1881
+ "first body is a whole group: a AND b pass"},
1882
+ {"<root xmlns=\"http://ex\"><c/></root>", 1, "the combined-in branch"},
1883
+ {"<root xmlns=\"http://ex\"><a/><c/></root>", 0,
1884
+ "mixing bodies: choice picks one branch, not both"},
1885
+ {"<root xmlns=\"http://ex\"><b/></root>", 0,
1886
+ "b alone: the group needs a first"},
1887
+ };
1888
+ for (auto& c : cases) {
1889
+ LeptrisDocument d = leptris_parse_string(c.doc, strlen(c.doc), &st);
1890
+ ASSERT_NE(d, nullptr) << c.doc;
1891
+ EXPECT_EQ(leptris_rng_validate(rng, d), c.want)
1892
+ << c.why << " — doc: " << c.doc;
1893
+ leptris_document_free(d);
1894
+ }
1895
+ leptris_rng_free(rng);
1896
+ }
1897
+
1898
+ TEST(Rng2088CombineMerge, InterleaveBranchesAreWholeBodies) {
1899
+ const char* schema =
1900
+ "<grammar ns=\"http://ex\" xmlns=\"http://relaxng.org/ns/structure/1.0\">"
1901
+ "<define name=\"content\">"
1902
+ "<element name=\"a\"><empty/></element>"
1903
+ "<element name=\"b\"><empty/></element>"
1904
+ "</define>"
1905
+ "<define name=\"content\" combine=\"interleave\">"
1906
+ "<element name=\"c\"><empty/></element>"
1907
+ "</define>"
1908
+ "<start><element name=\"root\"><ref name=\"content\"/></element></start>"
1909
+ "</grammar>";
1910
+ LeptrisRelaxNG rng =
1911
+ leptris_rng_parse(schema, strlen(schema), nullptr);
1912
+ ASSERT_NE(rng, nullptr);
1913
+ LeptrisStatus st = LEPTRIS_OK;
1914
+ struct { const char* doc; int want; const char* why; } cases[] = {
1915
+ {"<root xmlns=\"http://ex\"><a/><b/><c/></root>", 1,
1916
+ "a,b from the base group; c merged in — any order"},
1917
+ {"<root xmlns=\"http://ex\"><c/><b/><a/></root>", 0,
1918
+ "interleave frees order BETWEEN branches, not within a "
1919
+ "body's group (a precedes b)"},
1920
+ {"<root xmlns=\"http://ex\"><a/><c/></root>", 0,
1921
+ "b is required by the base group even merged"},
1922
+ };
1923
+ for (auto& c : cases) {
1924
+ LeptrisDocument d = leptris_parse_string(c.doc, strlen(c.doc), &st);
1925
+ ASSERT_NE(d, nullptr) << c.doc;
1926
+ EXPECT_EQ(leptris_rng_validate(rng, d), c.want)
1927
+ << c.why << " — doc: " << c.doc;
1928
+ leptris_document_free(d);
1929
+ }
1930
+ leptris_rng_free(rng);
1931
+ }
1932
+
1933
+ TEST(Rng2088CombineMerge, RepeatedChoiceMergeKeepsEarlierBodiesGrouped) {
1934
+ /* Three merge hops: base(a,b) + choice(c) + choice(d) — every
1935
+ * earlier body stays a whole group through the chain. */
1936
+ const char* schema =
1937
+ "<grammar ns=\"http://ex\" xmlns=\"http://relaxng.org/ns/structure/1.0\">"
1938
+ "<define name=\"content\">"
1939
+ "<element name=\"a\"><empty/></element>"
1940
+ "<element name=\"b\"><empty/></element>"
1941
+ "</define>"
1942
+ "<define name=\"content\" combine=\"choice\">"
1943
+ "<element name=\"c\"><empty/></element>"
1944
+ "</define>"
1945
+ "<define name=\"content\" combine=\"choice\">"
1946
+ "<element name=\"d\"><empty/></element>"
1947
+ "</define>"
1948
+ "<start><element name=\"root\"><ref name=\"content\"/></element></start>"
1949
+ "</grammar>";
1950
+ LeptrisRelaxNG rng =
1951
+ leptris_rng_parse(schema, strlen(schema), nullptr);
1952
+ ASSERT_NE(rng, nullptr);
1953
+ LeptrisStatus st = LEPTRIS_OK;
1954
+ struct { const char* doc; int want; const char* why; } cases[] = {
1955
+ {"<root xmlns=\"http://ex\"><a/><b/></root>", 1,
1956
+ "the original body through two merge hops"},
1957
+ {"<root xmlns=\"http://ex\"><c/></root>", 1, "hop 1's branch"},
1958
+ {"<root xmlns=\"http://ex\"><d/></root>", 1, "hop 2's branch"},
1959
+ {"<root xmlns=\"http://ex\"><b/></root>", 0, "b alone still rejects"},
1960
+ };
1961
+ for (auto& c : cases) {
1962
+ LeptrisDocument d = leptris_parse_string(c.doc, strlen(c.doc), &st);
1963
+ ASSERT_NE(d, nullptr) << c.doc;
1964
+ EXPECT_EQ(leptris_rng_validate(rng, d), c.want)
1965
+ << c.why << " — doc: " << c.doc;
1966
+ leptris_document_free(d);
1967
+ }
1968
+ leptris_rng_free(rng);
1969
+ }
@@ -2895,3 +2895,80 @@ TEST(XPathDynCall, NonTextCalleeRefusesWithoutCrash) {
2895
2895
 
2896
2896
  leptris_document_free(doc);
2897
2897
  }
2898
+
2899
+ /* SOTA C1 (nightly 44085294402, crash-cd79e090, fuzz_xslt): the
2900
+ * XQuery binding producers (for / switch / HOF params) appended raw
2901
+ * DOCUMENT nodes into nodesets flagged owns_synthetic_text=1 — the
2902
+ * flag lied. When a predicate later DROPPED such a member,
2903
+ * apply_predicates' dispose path freed a document-owned text node;
2904
+ * the document tree then dangled (the nightly's UAF read the freed
2905
+ * node from vm_apply_axis_child on a later axis step). The ownership
2906
+ * contract: a set flag asserts a fact about EVERY member of that
2907
+ * kind — producers that bind document nodes must leave the flag
2908
+ * false (document nodes are never disposed), and flag transfers move
2909
+ * exactly the owned members. These specs hold the two faces: the
2910
+ * dropped binding must not free the document, and a surviving
2911
+ * synthetic member must still be owned. */
2912
+ TEST(XPathDispose, ForLoopVarDropMustNotFreeDocumentText) {
2913
+ LeptrisStatus st = LEPTRIS_OK;
2914
+ LeptrisDocument doc =
2915
+ leptris_parse_string("<r><t>a</t><t>b</t></r>", 23, &st);
2916
+ ASSERT_NE(doc, nullptr);
2917
+ LeptrisElement root = leptris_document_root(doc);
2918
+ ASSERT_NE(root, nullptr);
2919
+
2920
+ /* The loop var binds the raw document text node; the body's
2921
+ * predicate drops it from the var set. */
2922
+ LeptrisXPathResult r =
2923
+ leptris_xpath_eval(doc, root,
2924
+ "for $x in /r/t/text() return $x[false()]");
2925
+ ASSERT_NE(r, nullptr) << "for-over-text with a false predicate errored";
2926
+
2927
+ /* The document must be intact after the drop. */
2928
+ LeptrisXPathResult c =
2929
+ leptris_xpath_eval(doc, root, "count(/r/t)");
2930
+ ASSERT_NE(c, nullptr);
2931
+ EXPECT_EQ(leptris_xpath_result_number(c), 2.0)
2932
+ << "the dropped var binding must not free document text nodes";
2933
+ leptris_xpath_result_free(c);
2934
+
2935
+ LeptrisXPathResult s =
2936
+ leptris_xpath_eval(doc, root, "string-join(/r/t/text(), '')");
2937
+ ASSERT_NE(s, nullptr);
2938
+ char* sv = leptris_xpath_result_string(s);
2939
+ ASSERT_NE(sv, nullptr);
2940
+ EXPECT_STREQ(sv, "ab") << "text content must survive the dropped binding";
2941
+ leptris_free_string(sv);
2942
+ leptris_xpath_result_free(s);
2943
+
2944
+ leptris_xpath_result_free(r);
2945
+ leptris_document_free(doc);
2946
+ }
2947
+
2948
+ TEST(XPathDispose, SwitchNodeCaseDropMustNotFreeDocumentText) {
2949
+ LeptrisStatus st = LEPTRIS_OK;
2950
+ LeptrisDocument doc =
2951
+ leptris_parse_string("<r><t>a</t><t>b</t></r>", 23, &st);
2952
+ ASSERT_NE(doc, nullptr);
2953
+ LeptrisElement root = leptris_document_root(doc);
2954
+ ASSERT_NE(root, nullptr);
2955
+
2956
+ /* A nodeset operand binds AS NODES into the case variable; the
2957
+ * arm's predicate drops every member of the binding. */
2958
+ LeptrisXPathResult r =
2959
+ leptris_xpath_eval(
2960
+ doc, root,
2961
+ "switch (/r/t/text()) case \"zz\" return 0"
2962
+ " default return $x[false()]");
2963
+ ASSERT_NE(r, nullptr) << "switch with a nodeset operand errored";
2964
+
2965
+ LeptrisXPathResult c =
2966
+ leptris_xpath_eval(doc, root, "count(/r/t)");
2967
+ ASSERT_NE(c, nullptr);
2968
+ EXPECT_EQ(leptris_xpath_result_number(c), 2.0)
2969
+ << "the case binding must not free document text nodes";
2970
+ leptris_xpath_result_free(c);
2971
+
2972
+ leptris_xpath_result_free(r);
2973
+ leptris_document_free(doc);
2974
+ }
@@ -3,6 +3,10 @@
3
3
  #include <gtest/gtest.h>
4
4
  #include <regex>
5
5
  #include <string>
6
+ #include <vector>
7
+ #ifndef _WIN32
8
+ #include <dirent.h>
9
+ #endif
6
10
  extern "C" {
7
11
  #ifndef _WIN32
8
12
  #include <unistd.h>
@@ -4649,3 +4653,79 @@ TEST(XsltCompile, EmptyMatchTemplateRefusedWithoutLeak) {
4649
4653
  ASSERT_EQ(x, nullptr) << "match=\"\" must fail the stylesheet";
4650
4654
  leptris_xslt_free(x);
4651
4655
  }
4656
+
4657
+ /* SOTA C1: the pinned fuzz corpus rides the suite. Every corpus
4658
+ * input goes through the harness body (parse -> apply to a seed doc
4659
+ * -> free), then a fresh predicate-heavy probe document exercises
4660
+ * the global xpath caches — the cross-input UAFs surface as stale
4661
+ * graph reuse on the NEXT evaluation, not inside the crashing
4662
+ * transform. ASan makes any stale read a hard failure. */
4663
+ TEST(XsltFuzzPins, CorpusInputsParseApplyFree) {
4664
+ #ifdef _WIN32
4665
+ GTEST_SKIP() << "POSIX dirent walk (the nightly harness covers Win32)";
4666
+ #else
4667
+ std::string here = __FILE__;
4668
+ std::string dir = here.substr(0, here.rfind("/xpath/")) +
4669
+ "/fuzz/corpus";
4670
+ DIR* d = opendir(dir.c_str());
4671
+ ASSERT_NE(d, nullptr) << "fuzz corpus dir missing: " << dir;
4672
+ std::vector<std::string> pins;
4673
+ struct dirent* e;
4674
+ while ((e = readdir(d)) != nullptr) {
4675
+ std::string n = e->d_name;
4676
+ if (n.size() > 4 && n.compare(n.size() - 4, 4, ".bin") == 0)
4677
+ pins.push_back(n);
4678
+ }
4679
+ closedir(d);
4680
+ ASSERT_FALSE(pins.empty()) << "no pinned inputs in " << dir;
4681
+
4682
+ static const char SEED[] =
4683
+ "<r><item>a</item><item>b</item></r>";
4684
+ for (const std::string& name : pins) {
4685
+ std::string path = dir + "/" + name;
4686
+ FILE* f = fopen(path.c_str(), "rb");
4687
+ ASSERT_NE(f, nullptr) << name;
4688
+ std::string input;
4689
+ char b[8192];
4690
+ size_t n;
4691
+ while ((n = fread(b, 1, sizeof b, f)) > 0) input.append(b, n);
4692
+ fclose(f);
4693
+ ASSERT_FALSE(input.empty()) << name;
4694
+
4695
+ LeptrisXslt xslt =
4696
+ leptris_xslt_parse(input.data(), input.size());
4697
+ if (xslt) {
4698
+ LeptrisStatus st = LEPTRIS_OK;
4699
+ LeptrisDocument doc =
4700
+ leptris_parse_string(SEED, sizeof(SEED) - 1, &st);
4701
+ if (doc) {
4702
+ LeptrisDocument out = leptris_xslt_apply(xslt, doc);
4703
+ if (out) leptris_document_free(out);
4704
+ leptris_document_free(doc);
4705
+ }
4706
+ leptris_xslt_free(xslt);
4707
+ }
4708
+
4709
+ /* The probe: the next consumer of the process-global caches
4710
+ * must see live graphs, not yesterday's freed ones. */
4711
+ LeptrisStatus pst = LEPTRIS_OK;
4712
+ static const char PROBE[] =
4713
+ "<r><x id='1'>p</x><x id='2'>q</x></r>";
4714
+ LeptrisDocument pdoc =
4715
+ leptris_parse_string(PROBE, sizeof(PROBE) - 1, &pst);
4716
+ ASSERT_NE(pdoc, nullptr) << name;
4717
+ LeptrisElement proot = leptris_document_root(pdoc);
4718
+ ASSERT_NE(proot, nullptr);
4719
+ LeptrisXPathResult pr =
4720
+ leptris_xpath_eval(pdoc, proot,
4721
+ "string-join(/r/x[@id]/text(), '')");
4722
+ ASSERT_NE(pr, nullptr) << "probe errored after " << name;
4723
+ char* psv = leptris_xpath_result_string(pr);
4724
+ ASSERT_NE(psv, nullptr);
4725
+ EXPECT_STREQ(psv, "pq") << "probe corrupted after " << name;
4726
+ leptris_free_string(psv);
4727
+ leptris_xpath_result_free(pr);
4728
+ leptris_document_free(pdoc);
4729
+ }
4730
+ #endif
4731
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
3
3
  "name": "leptris",
4
- "version": "1.9.427",
4
+ "version": "1.9.428",
5
5
  "description": "High-performance XML parser and XPath 1.0 engine in C (libleptris)",
6
6
  "homepage": "https://github.com/leptris/leptris",
7
7
  "license": "MIT",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leptris
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.427.0
4
+ version: 1.9.428.0
5
5
  platform: arm-linux
6
6
  authors:
7
7
  - Ribose Inc.
@@ -858,6 +858,7 @@ files:
858
858
  - vendor-src/libleptris/test/fixtures/malformed.xml
859
859
  - vendor-src/libleptris/test/fixtures/namespaces.xml
860
860
  - vendor-src/libleptris/test/fixtures/utf16_decl.xml
861
+ - vendor-src/libleptris/test/fuzz/corpus/encoding_decl_strstr_hbo.bin
861
862
  - vendor-src/libleptris/test/fuzz/corpus/gen/gen_0000.xsl
862
863
  - vendor-src/libleptris/test/fuzz/corpus/gen/gen_0001.xsl
863
864
  - vendor-src/libleptris/test/fuzz/corpus/gen/gen_0002.xsl
@@ -901,6 +902,8 @@ files:
901
902
  - vendor-src/libleptris/test/fuzz/corpus/html_foreign_cdata_short_opener.bin
902
903
  - vendor-src/libleptris/test/fuzz/corpus/seed1
903
904
  - vendor-src/libleptris/test/fuzz/corpus/seed2
905
+ - vendor-src/libleptris/test/fuzz/corpus/xpath_bracket_nesting_stack_overflow.bin
906
+ - vendor-src/libleptris/test/fuzz/corpus/xslt_apply_identity_recursion.bin
904
907
  - vendor-src/libleptris/test/fuzz/corpus/xslt_astcache_uaf_fold.bin
905
908
  - vendor-src/libleptris/test/fuzz/corpus/xslt_astcache_uaf_nightly.bin
906
909
  - vendor-src/libleptris/test/fuzz/corpus/xslt_astcache_uaf_session.bin
@@ -908,6 +911,7 @@ files:
908
911
  - vendor-src/libleptris/test/fuzz/corpus/xslt_dispatch_union_dup_hbo.bin
909
912
  - vendor-src/libleptris/test/fuzz/corpus/xslt_dyncall_nontext_callee_segv.xml
910
913
  - vendor-src/libleptris/test/fuzz/corpus/xslt_empty_match_template_leak.xml
914
+ - vendor-src/libleptris/test/fuzz/corpus/xslt_mixed_set_dispose_uaf.bin
911
915
  - vendor-src/libleptris/test/fuzz/corpus/xslt_uaf_predicate_layer.bin
912
916
  - vendor-src/libleptris/test/fuzz/corpus/xslt_union_number_head_segv.xml
913
917
  - vendor-src/libleptris/test/fuzz/fuzz_html.c
@@ -915,6 +919,7 @@ files:
915
919
  - vendor-src/libleptris/test/fuzz/fuzz_parse.c
916
920
  - vendor-src/libleptris/test/fuzz/fuzz_xpath.c
917
921
  - vendor-src/libleptris/test/fuzz/fuzz_xslt.c
922
+ - vendor-src/libleptris/test/fuzz/generators/gen_xml_seeds.py
918
923
  - vendor-src/libleptris/test/fuzz/generators/gen_xslt_seeds.py
919
924
  - vendor-src/libleptris/test/html/html5lib-redlist.txt
920
925
  - vendor-src/libleptris/test/html/html5lib-tests/LICENSE