leptris 1.9.426.1 → 1.9.427.0

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 (28) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/lib/leptris/vendor/aarch64-linux/libleptris.so +0 -0
  4. data/lib/leptris/vendor/aarch64-linux-musl/libleptris.so +0 -0
  5. data/lib/leptris/vendor/arm-linux/libleptris.so +0 -0
  6. data/lib/leptris/vendor/arm-linux-musl/libleptris.so +0 -0
  7. data/lib/leptris/vendor/arm64-darwin/libleptris.dylib +0 -0
  8. data/lib/leptris/vendor/ppc64le-linux/libleptris.so +0 -0
  9. data/lib/leptris/vendor/s390x-linux-musl/libleptris.so +0 -0
  10. data/lib/leptris/vendor/x86_64-darwin/libleptris.dylib +0 -0
  11. data/lib/leptris/vendor/x86_64-linux/libleptris.so +0 -0
  12. data/lib/leptris/vendor/x86_64-linux-musl/libleptris.so +0 -0
  13. data/lib/leptris/version.rb +1 -1
  14. data/vendor-src/README.md +1 -1
  15. data/vendor-src/libleptris/CHANGELOG.md +22 -0
  16. data/vendor-src/libleptris/CMakeLists.txt +1 -1
  17. data/vendor-src/libleptris/src/leptris/rng/validate.c +284 -40
  18. data/vendor-src/libleptris/src/leptris/xpath/vm.c +18 -9
  19. data/vendor-src/libleptris/src/leptris/xpath/xpath_compiled.c +13 -1
  20. data/vendor-src/libleptris/src/leptris/xslt/xslt_parse.c +20 -0
  21. data/vendor-src/libleptris/test/differential/rs-runner/Cargo.toml +1 -1
  22. data/vendor-src/libleptris/test/fuzz/corpus/xslt_astcache_uaf_session.bin +0 -0
  23. data/vendor-src/libleptris/test/fuzz/corpus/xslt_carrier_number_uaf.bin +1 -0
  24. data/vendor-src/libleptris/test/fuzz/corpus/xslt_dispatch_union_dup_hbo.bin +0 -0
  25. data/vendor-src/libleptris/test/fuzz/corpus/xslt_uaf_predicate_layer.bin +0 -0
  26. data/vendor-src/libleptris/test/rng/test_rng.cpp +179 -0
  27. data/vendor-src/libleptris/vcpkg.json +1 -1
  28. metadata +5 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '058d750a99a236e72244d6bf0d3ba480977a41d2db3b16af1518a95b2d44f90c'
4
- data.tar.gz: 4683259d4aea8f5c1fa327cfc46597c6c1015375b9332b943bc755ff628132ed
3
+ metadata.gz: 0d65cdd88b3f3d4f710de38dcdd83362fb63a4ceca4cc1073726bde27d347b22
4
+ data.tar.gz: 7c1c5aa5da8f2245e5be62e7cdae064ab2e6433373296c09d878b02e3ae88e78
5
5
  SHA512:
6
- metadata.gz: e59ee5e77e348ca7ad9a80b3def04134df54994b70a0ec60049ea8a36b50ffd71fe264bf1596623d9561f3c7857b85a391e7fef22bcda25e1f3b943831d5dd49
7
- data.tar.gz: 61ce4d516c348a786c1d17bbe2dae2f939f395ada5215bfce2f57d9526cfea0537243a4586082c9c8bb692d14d6dd66b85ef67e66156742dab6c1419f17b6952
6
+ metadata.gz: 9e16d00ec396d67c124fd89575a027a9b33597c6699856534f54209ac7d49ca31d85e10060ec92947417b0cdd65e82b3bb44b3644479fcec54e10d038c1504b8
7
+ data.tar.gz: e9825fea2edf9c36df22c39b99f390099273ed6617e0d15562acbcbd71839fe78c8274407f89adc6600c5632add847aa530e85eded84afe55af9d8d0c82c6783
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.426"
11
+ LIBLEPTRIS_VERSION = "1.9.427"
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.426.1"
4
+ VERSION = "1.9.427.0"
5
5
  end
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.426
4
+ - libleptris v1.9.427
5
5
  - utf8proc v2.11.0
6
6
 
7
7
  Rebuild by hand:
@@ -1,5 +1,27 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.9.427] - 2026-11-18
4
+
5
+ ### Fixed
6
+
7
+ The fuzz-lane's memory-safety wave plus the OpenMath2 RELAX NG
8
+ conformance wave — seven fixes in two days, every one from a
9
+ standalone-reproducible input.
10
+
11
+ - **xpath: the bytecode compiled from the wrong cache graph** (SOTA C1 finding 6, the last edge). Same expression text can hold different parses in different cache records — a compiled handle may carry the graveyard's graph (its insert pinned a pre-eviction parse) while the live slot holds a fresher one. The eval path compiled bytecode from the handle's graph but stored it under the expression key, so the slot's later holders ran bytecode whose constants pointed into a graph only the old handle kept alive, and the handle's teardown freed it under them. The bytecode now compiles from **the slot's own graph**; the crash regime went from 90-seconds-to-UAF to 2.2M clean runs.
12
+ - **xslt: the dispatch key lists dedupe their templates** (SOTA C1 finding 7). `match="…|t|…|t"` names the same leaf twice; every alternative appended the same template to the same dispatch key, running `k->n` past the allocation (heap-buffer-overflow at stylesheet parse). Both append sites dedupe per key — which also stops a template dispatching twice per node.
13
+ - **xpath: the union transfers ownership per side** (SOTA C1 finding 8). The union concatenated one leg when the other operand was empty but gated the #514 ownership transfer on both legs — a carrier nodeset unioned with an empty operand left the result sharing an owned node the owning operand freed at cleanup. The transfer is per side.
14
+ - **rng: wrapper bodies match as implicit groups** (#2078). `optional`/`zeroOrMore`/`oneOrMore` matched only their first child; the XML form flattens multi-child wrapper bodies as siblings (Jing §4.10) — openmath2.rng's OMATP `(a,b)+` rejected `<a/><b/>` while claiming to expect `b`. The three wrappers walk the whole child chain; `oneOrMore` repeats it whole.
15
+ - **rng: a choice of attributes selects exactly one branch as a set** (#2079). Per-attribute existence over the union of branches admitted `dec` AND `hex` together on OMF while the required pass demanded both. The attribute walkers carry a selection map (one branch per attr-choice, refs expanded, bounded search); a branch walks as a single node — the choice's children are siblings, and the old list walk crossed branches.
16
+ - **rng: `<data>` content lexes through the XSD builtin library** (#2080). `data_lexical_ok` handled only `integer`; base64Binary validated `not-base64!!!`. Known XSD types route through the engine's builtin lexers — one shared lexical space with the XSD validator (base64 padding/remainder rules, hex even-length; unknown types stay permissive per the RNG fallback contract).
17
+
18
+ ### Tooling
19
+
20
+ - The C1 lane's corpus now carries every pinned input from all eight findings (four UAF/SEGV classes, one overflow, two RNG conformance shapes); the nightly's grammar-aware generator regenerates 200 deep structures per run over them.
21
+
22
+
23
+
24
+
3
25
  ## [1.9.426] - 2026-11-17
4
26
 
5
27
  ### Fixed
@@ -3,7 +3,7 @@
3
3
  cmake_minimum_required(VERSION 3.20)
4
4
 
5
5
  project(leptris
6
- VERSION 1.9.426
6
+ VERSION 1.9.427
7
7
  DESCRIPTION "Fast XML parser and XPath evaluator in pure C"
8
8
  LANGUAGES C CXX
9
9
  )
@@ -10,6 +10,9 @@
10
10
  */
11
11
  #include "rng_internal.h"
12
12
  #include "../dom/element.h"
13
+ /* #2080: <data> content lexes through the engine's XSD builtin
14
+ * library — one shared lexical space with the XSD validator. */
15
+ #include "../xsd/xsd_internal.h"
13
16
  #include <stdarg.h>
14
17
  #include <stdlib.h>
15
18
  #include <string.h>
@@ -126,6 +129,16 @@ static int data_lexical_ok(const RngPattern* data, const char* t) {
126
129
  for (; *q; q++)
127
130
  if (!isdigit((unsigned char)*q)) return 0;
128
131
  }
132
+ /* leptris#2080: <data> content lexes through the XSD builtin
133
+ * library — the engine's own lexical space (base64Binary admitted
134
+ * "not-base64!!!" before this; the datatypeLibrary default is the
135
+ * XSD datatypes). Unknown types stay permissive. */
136
+ if (data->datatype && *data->datatype) {
137
+ char qname[64];
138
+ snprintf(qname, sizeof(qname), "xs:%s", data->datatype);
139
+ if (xsd_builtin_known(qname))
140
+ return xsd_builtin_valid(qname, t) == 1;
141
+ }
129
142
  return 1;
130
143
  }
131
144
 
@@ -313,13 +326,134 @@ static int list_consumes_attr(RngVal* v, RngPattern* head,
313
326
  return 0;
314
327
  }
315
328
 
316
- /* Check the attribute patterns against e's actual attributes. */
329
+ /* ---- ruby#2079: whole-branch attribute-choice selection ----------
330
+ * A <choice> of attribute branches must pick EXACTLY ONE branch as
331
+ * a set: per-attribute existence over the union of branches let
332
+ * attributes from different branches combine (openmath2.rng's OMF
333
+ * admitted dec AND hex). The selection map assigns one branch per
334
+ * attr-choice node; the walkers consult it. Unassigned choices keep
335
+ * the union semantics (collection contexts). */
336
+ #define RNG_ATTR_SEL_MAX 16
337
+ #define RNG_ATTR_SEARCH_MAX_DEPTH 12
338
+
339
+ typedef struct {
340
+ RngPattern* choice;
341
+ RngPattern* branch;
342
+ } AttrSelEntry;
343
+ typedef struct {
344
+ AttrSelEntry e[RNG_ATTR_SEL_MAX];
345
+ size_t n;
346
+ } AttrSel;
347
+
348
+ static int check_required_list_sel(RngVal* v, RngPattern* head,
349
+ LeptrisElement e, const AttrSel* sel);
317
350
  static int check_required_list(RngVal* v, RngPattern* head,
318
351
  LeptrisElement e) {
352
+ return check_required_list_sel(v, head, e, NULL);
353
+ }
354
+
355
+ static RngPattern* attr_sel_branch(const AttrSel* sel,
356
+ const RngPattern* choice) {
357
+ if (!sel) return NULL;
358
+ for (size_t i = 0; i < sel->n; i++)
359
+ if (sel->e[i].choice == choice) return sel->e[i].branch;
360
+ return NULL;
361
+ }
362
+
363
+ static int list_consumes_attr_sel(RngVal* v, RngPattern* head,
364
+ LeptrisElement e, const char* name,
365
+ const AttrSel* sel);
366
+ static int pattern_consumes_attr_sel(RngVal* v, RngPattern* p,
367
+ LeptrisElement e, const char* name,
368
+ const AttrSel* sel) {
369
+ if (sel) {
370
+ RngPattern* b = attr_sel_branch(sel, p);
371
+ if (p->kind == RNG_CHOICE && b)
372
+ return list_consumes_attr_sel(v, b, e, name, sel);
373
+ if (p->kind == RNG_CHOICE && !b && p->first_child &&
374
+ p->first_child->kind == RNG_ATTRIBUTE &&
375
+ !p->first_child->next) {
376
+ /* A single-attribute choice with no assignment is
377
+ * decided by the attribute itself (its own union). */
378
+ }
379
+ }
380
+ return list_consumes_attr_sel(v, p->first_child, e, name, sel);
381
+ }
382
+
383
+ static int node_consumes_attr_sel(RngVal* v, RngPattern* c,
384
+ LeptrisElement e, const char* name,
385
+ const AttrSel* sel);
386
+ static int list_consumes_attr_sel(RngVal* v, RngPattern* head,
387
+ LeptrisElement e, const char* name,
388
+ const AttrSel* sel) {
319
389
  for (RngPattern* c = head; c; c = c->next) {
390
+ if (node_consumes_attr_sel(v, c, e, name, sel)) return 1;
391
+ }
392
+ return 0;
393
+ }
394
+
395
+ /* ONE node — a branch selection must not walk the sibling chain
396
+ * (ruby#2079: the choice's children are siblings; a branch walk that
397
+ * follows ->next crosses into the OTHER branches). */
398
+ static int node_consumes_attr_sel(RngVal* v, RngPattern* c,
399
+ LeptrisElement e, const char* name,
400
+ const AttrSel* sel) {
401
+ {
402
+ switch (c->kind) {
403
+ case RNG_ATTRIBUTE:
404
+ if (c->any_name) {
405
+ const char* got = leptris_element_attribute(e, name);
406
+ return attr_content_satisfied(v, c, got ? got : "");
407
+ }
408
+ if (c->name && strcmp(c->name, name) == 0) {
409
+ const char* got = leptris_element_attribute(e, name);
410
+ return attr_content_satisfied(v, c, got ? got : "");
411
+ }
412
+ break;
413
+ case RNG_OPTIONAL: case RNG_ZERO_OR_MORE:
414
+ case RNG_GROUP: case RNG_INTERLEAVE:
415
+ if (pattern_consumes_attr_sel(v, c, e, name, sel)) return 1;
416
+ break;
417
+ case RNG_CHOICE: {
418
+ RngPattern* b = attr_sel_branch(sel, c);
419
+ if (b) {
420
+ if (node_consumes_attr_sel(v, b, e, name, sel))
421
+ return 1;
422
+ break;
423
+ }
424
+ /* Unassigned: union semantics (collection contexts). */
425
+ if (pattern_consumes_attr(v, c, e, name)) return 1;
426
+ break;
427
+ }
428
+ case RNG_REF: {
429
+ RngDefine* d = find_define(v->g, c->name);
430
+ if (d && d->body &&
431
+ list_consumes_attr_sel(v, d->body, e, name, sel))
432
+ return 1;
433
+ break;
434
+ }
435
+ default: break;
436
+ }
437
+ }
438
+ return 0;
439
+ }
440
+
441
+ static int check_required_node_sel(RngVal* v, RngPattern* c,
442
+ LeptrisElement e, const AttrSel* sel);
443
+ static int check_required_list_sel(RngVal* v, RngPattern* head,
444
+ LeptrisElement e, const AttrSel* sel) {
445
+ for (RngPattern* c = head; c; c = c->next) {
446
+ if (!check_required_node_sel(v, c, e, sel)) return 0;
447
+ }
448
+ return 1;
449
+ }
450
+
451
+ static int check_required_node_sel(RngVal* v, RngPattern* c,
452
+ LeptrisElement e, const AttrSel* sel) {
453
+ {
320
454
  switch (c->kind) {
321
455
  case RNG_ATTRIBUTE: {
322
- if (c->any_name) break; /* wildcard: satisfiable */
456
+ if (c->any_name) break;
323
457
  const char* got = leptris_element_attribute(e, c->name);
324
458
  if (!got) {
325
459
  diag(v, LEPTRIS_DIAG_MISSING_REQUIRED_ATTR, e,
@@ -330,33 +464,121 @@ static int check_required_list(RngVal* v, RngPattern* head,
330
464
  break;
331
465
  }
332
466
  case RNG_GROUP: case RNG_INTERLEAVE: case RNG_ONE_OR_MORE:
333
- if (!check_required_list(v, c->first_child, e)) return 0;
467
+ if (!check_required_list_sel(v, c->first_child, e, sel))
468
+ return 0;
334
469
  break;
335
470
  case RNG_REF: {
336
- /* #1164: a required attribute behind <ref> is as
337
- * required as an inline one — metanorma bibdata
338
- * schemas are ref'd attribute groups throughout */
339
471
  RngDefine* d = find_define(v->g, c->name);
340
472
  if (d && d->body &&
341
- !check_required_list(v, d->body, e))
473
+ !check_required_list_sel(v, d->body, e, sel))
342
474
  return 0;
343
475
  break;
344
476
  }
345
- case RNG_CHOICE:
346
- /* Simplified: any alternative with all its attrs. */
347
- if (!check_required_list(v, c->first_child, e)) return 0;
477
+ case RNG_CHOICE: {
478
+ RngPattern* b = attr_sel_branch(sel, c);
479
+ if (b) {
480
+ if (!check_required_node_sel(v, b, e, sel)) return 0;
481
+ break;
482
+ }
483
+ int any_ok = 0;
484
+ for (RngPattern* alt = c->first_child; alt && !any_ok;
485
+ alt = alt->next) {
486
+ v->failed = 0;
487
+ v->err[0] = 0;
488
+ any_ok = check_required_list_sel(v, alt, e, sel);
489
+ }
490
+ if (!any_ok) return 0;
348
491
  break;
492
+ }
349
493
  default: break;
350
494
  }
351
495
  }
352
496
  return 1;
353
497
  }
354
498
 
355
- static int check_required_attrs(RngVal* v, RngPattern* p, LeptrisElement e) {
356
- return check_required_list(v, p->first_child, e);
499
+ /* Collect the attr-consuming CHOICE nodes through the content
500
+ * (refs expanded, depth-capped). */
501
+ static void collect_attr_choices(RngVal* v, RngPattern* p, int depth,
502
+ AttrSel* out) {
503
+ if (!p || depth > 24) return;
504
+ for (RngPattern* c = p->first_child; c; c = c->next) {
505
+ if (c->kind == RNG_CHOICE) {
506
+ int consumes = 0;
507
+ for (RngPattern* b = c->first_child; b && !consumes;
508
+ b = b->next)
509
+ if (b->kind == RNG_ATTRIBUTE) consumes = 1;
510
+ if (consumes && out->n < RNG_ATTR_SEL_MAX) {
511
+ out->e[out->n].choice = c;
512
+ out->e[out->n].branch = NULL;
513
+ out->n++;
514
+ }
515
+ }
516
+ if (c->kind == RNG_REF) {
517
+ RngDefine* d = find_define(v->g, c->name);
518
+ if (d && d->body) collect_attr_choices(v, d->body, depth + 1, out);
519
+ continue;
520
+ }
521
+ collect_attr_choices(v, c, depth + 1, out);
522
+ }
523
+ }
524
+
525
+ static int check_required_attrs_sel(RngVal* v, RngPattern* p,
526
+ LeptrisElement e, const AttrSel* sel) {
527
+ return check_required_list_sel(v, p->first_child, e, sel);
528
+ }
529
+
530
+ /* One candidate assignment: every instance attribute consumed, every
531
+ * requirement satisfied — under THIS selection. */
532
+ static int match_attrs_with_sel(RngVal* v, RngPattern* content,
533
+ LeptrisElement e, const AttrSel* sel) {
534
+ v->failed = 0;
535
+ v->err[0] = 0;
536
+ for (struct leptris_attribute* a =
537
+ leptris_element_get_first_attribute(e);
538
+ a; a = leptris_attr_next(a)) {
539
+ if (!pattern_consumes_attr_sel(v, content, e, attr_cname(a), sel))
540
+ return 0;
541
+ }
542
+ return check_required_attrs_sel(v, content, e, sel);
543
+ }
544
+
545
+ /* The bounded assignment search: one branch per attr-choice. */
546
+ static int attr_sel_search(RngVal* v, RngPattern* content,
547
+ LeptrisElement e, AttrSel* sel, int depth) {
548
+ if (depth > RNG_ATTR_SEARCH_MAX_DEPTH) return 0;
549
+ for (size_t i = 0; i < sel->n; i++) {
550
+ if (sel->e[i].branch) continue;
551
+ for (RngPattern* b = sel->e[i].choice->first_child; b;
552
+ b = b->next) {
553
+ sel->e[i].branch = b;
554
+ v->failed = 0;
555
+ v->err[0] = 0;
556
+ if (attr_sel_search(v, content, e, sel, depth + 1)) return 1;
557
+ sel->e[i].branch = NULL;
558
+ }
559
+ return 0;
560
+ }
561
+ return match_attrs_with_sel(v, content, e, sel);
562
+ }
563
+
564
+ static int check_required_attrs(RngVal* v, RngPattern* p,
565
+ LeptrisElement e) {
566
+ return check_required_list_sel(v, p->first_child, e, NULL);
357
567
  }
358
568
 
359
569
  static int match_attrs(RngVal* v, RngPattern* content, LeptrisElement e) {
570
+ /* ruby#2079: attr-consuming choices exist → whole-branch
571
+ * selection search. Otherwise the union path is exact. */
572
+ AttrSel sel;
573
+ memset(&sel, 0, sizeof(sel));
574
+ collect_attr_choices(v, content, 0, &sel);
575
+ if (sel.n > 0) {
576
+ if (attr_sel_search(v, content, e, &sel, 0)) return 1;
577
+ diag(v, LEPTRIS_DIAG_ATTR_NOT_ALLOWED, e,
578
+ "attribute combination matches no branch of the "
579
+ "attribute choice", NULL);
580
+ return 0;
581
+ }
360
582
  /* Every instance attribute must be consumed by the content. */
361
583
  for (struct leptris_attribute* a = leptris_element_get_first_attribute(e);
362
584
  a; a = leptris_attr_next(a)) {
@@ -492,44 +714,66 @@ static size_t match_seq(RngVal* v, RngPattern* p, LeptrisNodeRef* kids,
492
714
  return i;
493
715
  }
494
716
  case RNG_OPTIONAL: {
495
- size_t r = match_seq(v, p->first_child, kids, n, idx);
496
- if (r == (size_t)-1) {
497
- /* The branch is skippable: an inner mismatch is
498
- * speculative, not a failure — clear the latch like
499
- * ZERO_OR_MORE/CHOICE do, or the stuck failure
500
- * poisons every later match (regression since the
501
- * #878 vocabulary pass made silent mismatches
502
- * loud; optional-omitted documents validated
503
- * false). */
504
- v->failed = 0;
505
- v->err[0] = 0;
506
- return idx;
717
+ /* ruby-adjacent leptris#2078: the XML form flattens a
718
+ * multi-child wrapper body as siblings — an implicit
719
+ * group (Jing §4.10). Walk the WHOLE child chain; the
720
+ * old first_child-only hand dropped every sibling past
721
+ * the first (openmath2.rng's OMATP). */
722
+ size_t i = idx;
723
+ for (RngPattern* c = p->first_child; c; c = c->next) {
724
+ i = match_seq(v, c, kids, n, i);
725
+ if (i == (size_t)-1) {
726
+ /* The branch is skippable: an inner mismatch is
727
+ * speculative, not a failure — clear the latch like
728
+ * ZERO_OR_MORE/CHOICE do, or the stuck failure
729
+ * poisons every later match (regression since the
730
+ * #878 vocabulary pass made silent mismatches
731
+ * loud; optional-omitted documents validated
732
+ * false). */
733
+ v->failed = 0;
734
+ v->err[0] = 0;
735
+ return idx;
736
+ }
507
737
  }
508
- return r;
738
+ return i;
509
739
  }
510
740
  case RNG_ZERO_OR_MORE: {
511
741
  for (;;) {
512
- size_t r = match_seq(v, p->first_child, kids, n, idx);
513
- if (r == (size_t)-1 || r == idx) {
514
- v->failed = 0;
515
- v->err[0] = 0;
516
- return idx;
742
+ size_t i = idx;
743
+ for (RngPattern* c = p->first_child; c; c = c->next) {
744
+ i = match_seq(v, c, kids, n, i);
745
+ if (i == (size_t)-1) {
746
+ v->failed = 0;
747
+ v->err[0] = 0;
748
+ return idx;
749
+ }
517
750
  }
518
- idx = r;
751
+ if (i == idx) return idx;
752
+ idx = i;
519
753
  }
520
754
  }
521
755
  case RNG_ONE_OR_MORE: {
522
- size_t r = match_seq(v, p->first_child, kids, n, idx);
523
- if (r == (size_t)-1) return (size_t)-1;
524
- idx = r;
756
+ /* First iteration: the whole implicit-group body must
757
+ * match (#2078). */
758
+ size_t i = idx;
759
+ for (RngPattern* c = p->first_child; c; c = c->next) {
760
+ i = match_seq(v, c, kids, n, i);
761
+ if (i == (size_t)-1) return (size_t)-1;
762
+ }
763
+ /* Subsequent iterations: repeat the body while it makes
764
+ * progress. */
525
765
  for (;;) {
526
- r = match_seq(v, p->first_child, kids, n, idx);
527
- if (r == (size_t)-1 || r == idx) {
528
- v->failed = 0;
529
- v->err[0] = 0;
530
- return idx;
766
+ size_t j = i;
767
+ for (RngPattern* c = p->first_child; c; c = c->next) {
768
+ j = match_seq(v, c, kids, n, j);
769
+ if (j == (size_t)-1) {
770
+ v->failed = 0;
771
+ v->err[0] = 0;
772
+ return i;
773
+ }
531
774
  }
532
- idx = r;
775
+ if (j == i) return i;
776
+ i = j;
533
777
  }
534
778
  }
535
779
  case RNG_EMPTY:
@@ -1622,18 +1622,27 @@ static int vm_apply_binary_op(XPathVM* vm, XPathContext* ctx,
1622
1622
 
1623
1623
  /* Issue #514: transfer synthetic-node ownership from
1624
1624
  * the operands — see the twin fix in
1625
- * evaluator_operators.c. */
1626
- if (ln && rn) {
1627
- result->value.nodeset_value->owns_attributes =
1628
- ln->owns_attributes || rn->owns_attributes;
1629
- result->value.nodeset_value->owns_namespaces =
1630
- ln->owns_namespaces || rn->owns_namespaces;
1631
- result->value.nodeset_value->owns_synthetic_text =
1632
- ln->owns_synthetic_text ||
1633
- rn->owns_synthetic_text;
1625
+ * evaluator_operators.c. PER SIDE (finding 8): the
1626
+ * concat above runs on one leg when the other is
1627
+ * empty (rn/ln NULL), and gating the transfer on
1628
+ * `ln && rn` left the result sharing an owned node
1629
+ * the owning operand still freed at cleanup — the
1630
+ * pushed result handed out disposed memory. */
1631
+ result->value.nodeset_value->owns_attributes =
1632
+ (ln ? ln->owns_attributes : 0) ||
1633
+ (rn ? rn->owns_attributes : 0);
1634
+ result->value.nodeset_value->owns_namespaces =
1635
+ (ln ? ln->owns_namespaces : 0) ||
1636
+ (rn ? rn->owns_namespaces : 0);
1637
+ result->value.nodeset_value->owns_synthetic_text =
1638
+ (ln ? ln->owns_synthetic_text : 0) ||
1639
+ (rn ? rn->owns_synthetic_text : 0);
1640
+ if (ln) {
1634
1641
  ln->owns_attributes = 0;
1635
1642
  ln->owns_namespaces = 0;
1636
1643
  ln->owns_synthetic_text = 0;
1644
+ }
1645
+ if (rn) {
1637
1646
  rn->owns_attributes = 0;
1638
1647
  rn->owns_namespaces = 0;
1639
1648
  rn->owns_synthetic_text = 0;
@@ -77,7 +77,19 @@ static struct leptris_xpath_result* compiled_eval_bc_pinned(
77
77
  &ce);
78
78
  LeptrisXPathBytecode* bc = hit ? ce.bc : NULL;
79
79
  if (hit && !bc) {
80
- bc = leptris_xpath_compile_ast(compiled->ast);
80
+ /* Finding 6, the last edge: compile from THE SLOT'S graph
81
+ * (ce.ast), never from compiled->ast. Same expression text
82
+ * can have DIFFERENT parses in different records: this
83
+ * compiled handle may hold the graveyard's graph (its insert
84
+ * pinned a pre-eviction parse) while the live slot holds a
85
+ * fresher parse of the same text. Bytecode compiled from
86
+ * compiled->ast but STORED into the slot paired its constants
87
+ * with a graph the slot does not own — the slot's later
88
+ * holders ran bytecode whose constants pointed into a graph
89
+ * only the old handle kept alive, and the handle's teardown
90
+ * freed that graph under them (the nightly's UAF at
91
+ * evaluate_function_call_impl). */
92
+ bc = leptris_xpath_compile_ast(ce.ast);
81
93
  if (bc) {
82
94
  xpath_ast_cache_store_bc(compiled->expr,
83
95
  compiled->expr_len, bc);
@@ -2012,6 +2012,15 @@ void xslt_sheet_build_dispatch(XsltStylesheet* sheet) {
2012
2012
  n * sizeof(XsltTemplate*));
2013
2013
  if (!k2->list) continue;
2014
2014
  }
2015
+ /* Finding 7, the value-index twin: same
2016
+ * dedupe (a template can carry two identical
2017
+ * [@k='v'] alternatives). */
2018
+ {
2019
+ int dup = 0;
2020
+ for (size_t i = 0; i < k2->n && !dup; i++)
2021
+ dup = (k2->list[i] == t);
2022
+ if (dup) continue;
2023
+ }
2015
2024
  k2->list[k2->n++] = t;
2016
2025
  continue;
2017
2026
  }
@@ -2042,6 +2051,17 @@ void xslt_sheet_build_dispatch(XsltStylesheet* sheet) {
2042
2051
  n * sizeof(XsltTemplate*));
2043
2052
  if (!k->list) continue;
2044
2053
  }
2054
+ /* Finding 7 (the fuzzer's "a|…|t|…|t" unions): a
2055
+ * template can name the same leaf in SEVERAL
2056
+ * alternatives, and every append grew k->n past
2057
+ * the n-sized list. A template also must not be
2058
+ * dispatched twice per node — dedupe per key. */
2059
+ {
2060
+ int dup = 0;
2061
+ for (size_t i = 0; i < k->n && !dup; i++)
2062
+ dup = (k->list[i] == t);
2063
+ if (dup) continue;
2064
+ }
2045
2065
  k->list[k->n++] = t;
2046
2066
  }
2047
2067
  if (has_other) {
@@ -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.6.20"
14
+ leptris = "=1.7.1"
15
15
  sha2 = "0.10"
16
16
 
17
17
  [profile.release]
@@ -0,0 +1 @@
1
+ <xsl:stylesheet xion="1.0"><xsl:template match="/"><xsl:for-each select="item/r[@mode]-[lmerge-acast()]|6'deapply-templatund(nude(mr@ib))"/></xsl:template></xsl:stylesheet>
@@ -1670,3 +1670,182 @@ TEST(Rng1709Shapes, AttributeChoiceWithTextBranchAcceptsAny) {
1670
1670
  * definition here, but the harness shape keeps it simple — the
1671
1671
  * enum hit and text hit are the contract under test. */
1672
1672
  }
1673
+
1674
+ /* ---- leptris#2078: wrapper bodies are implicit groups ------------- */
1675
+
1676
+ TEST(Rng2078Wrappers, OneOrMoreOverMultiElementBody) {
1677
+ /* Jing §4.10: the XML form flattens a multi-child wrapper body as
1678
+ * siblings — an implicit group. match_seq handed the wrapper only
1679
+ * first_child, so the sibling chain past the first element was
1680
+ * never matched (openmath2.rng's OMATP shape). */
1681
+ const char* schema =
1682
+ "<element name=\"root\" xmlns=\"http://relaxng.org/ns/structure/1.0\">"
1683
+ "<oneOrMore>"
1684
+ "<element name=\"a\"><empty/></element>"
1685
+ "<element name=\"b\"><empty/></element>"
1686
+ "</oneOrMore></element>";
1687
+ LeptrisRelaxNG rng =
1688
+ leptris_rng_parse(schema, strlen(schema), nullptr);
1689
+ ASSERT_NE(rng, nullptr);
1690
+ LeptrisStatus st = LEPTRIS_OK;
1691
+ LeptrisDocument d = leptris_parse_string(
1692
+ "<root><a/><b/></root>", strlen("<root><a/><b/></root>"), &st);
1693
+ ASSERT_NE(d, nullptr);
1694
+ EXPECT_EQ(leptris_rng_validate(rng, d), 1)
1695
+ << "oneOrMore over an (a,b) body must accept <a/><b/>";
1696
+ leptris_document_free(d);
1697
+ d = leptris_parse_string(
1698
+ "<root><a/><b/><a/><b/></root>", 29, &st);
1699
+ ASSERT_NE(d, nullptr);
1700
+ EXPECT_EQ(leptris_rng_validate(rng, d), 1)
1701
+ << "the repetition must cover the WHOLE body per iteration";
1702
+ leptris_document_free(d);
1703
+ d = leptris_parse_string("<root><a/></root>", 17, &st);
1704
+ ASSERT_NE(d, nullptr);
1705
+ EXPECT_EQ(leptris_rng_validate(rng, d), 0)
1706
+ << "a half-iteration (a without b) must still reject";
1707
+ leptris_document_free(d);
1708
+ leptris_rng_free(rng);
1709
+ }
1710
+
1711
+ TEST(Rng2078Wrappers, OptionalOverMultiElementBody) {
1712
+ const char* schema =
1713
+ "<element name=\"root\" xmlns=\"http://relaxng.org/ns/structure/1.0\">"
1714
+ "<optional>"
1715
+ "<element name=\"a\"><empty/></element>"
1716
+ "<element name=\"b\"><empty/></element>"
1717
+ "</optional></element>";
1718
+ LeptrisRelaxNG rng =
1719
+ leptris_rng_parse(schema, strlen(schema), nullptr);
1720
+ ASSERT_NE(rng, nullptr);
1721
+ LeptrisStatus st = LEPTRIS_OK;
1722
+ /* present as a unit: accept; absent: accept; half-present: reject */
1723
+ const char* ok1 = "<root><a/><b/></root>";
1724
+ const char* ok2 = "<root/>";
1725
+ const char* bad = "<root><a/></root>";
1726
+ LeptrisDocument d = leptris_parse_string(ok1, strlen(ok1), &st);
1727
+ ASSERT_NE(d, nullptr);
1728
+ EXPECT_EQ(leptris_rng_validate(rng, d), 1);
1729
+ leptris_document_free(d);
1730
+ d = leptris_parse_string(ok2, strlen(ok2), &st);
1731
+ ASSERT_NE(d, nullptr);
1732
+ EXPECT_EQ(leptris_rng_validate(rng, d), 1);
1733
+ leptris_document_free(d);
1734
+ d = leptris_parse_string(bad, strlen(bad), &st);
1735
+ ASSERT_NE(d, nullptr);
1736
+ EXPECT_EQ(leptris_rng_validate(rng, d), 0);
1737
+ leptris_document_free(d);
1738
+ leptris_rng_free(rng);
1739
+ }
1740
+
1741
+ TEST(Rng2078Wrappers, ZeroOrMoreOverMultiElementBody) {
1742
+ const char* schema =
1743
+ "<element name=\"root\" xmlns=\"http://relaxng.org/ns/structure/1.0\">"
1744
+ "<zeroOrMore>"
1745
+ "<element name=\"a\"><empty/></element>"
1746
+ "<element name=\"b\"><empty/></element>"
1747
+ "</zeroOrMore></element>";
1748
+ LeptrisRelaxNG rng =
1749
+ leptris_rng_parse(schema, strlen(schema), nullptr);
1750
+ ASSERT_NE(rng, nullptr);
1751
+ LeptrisStatus st = LEPTRIS_OK;
1752
+ const char* doc1 = "<root><a/><b/><a/></root>"; /* trailing half: reject */
1753
+ LeptrisDocument d = leptris_parse_string(
1754
+ "<root><a/><b/></root>", strlen("<root><a/><b/></root>"), &st);
1755
+ ASSERT_NE(d, nullptr);
1756
+ EXPECT_EQ(leptris_rng_validate(rng, d), 1);
1757
+ leptris_document_free(d);
1758
+ d = leptris_parse_string(doc1, strlen(doc1), &st);
1759
+ ASSERT_NE(d, nullptr);
1760
+ EXPECT_EQ(leptris_rng_validate(rng, d), 0)
1761
+ << "a whole-body iteration cannot end mid-body";
1762
+ leptris_document_free(d);
1763
+ leptris_rng_free(rng);
1764
+ }
1765
+
1766
+ /* ---- leptris#2079: a choice of attributes is exclusive ------------ */
1767
+
1768
+ TEST(Rng2079AttrChoice, ExactlyOneBranchWins) {
1769
+ /* openmath2.rng's OMF: <choice> of dec(hex? no—double) and hex —
1770
+ * per-attribute existence over the union of branches admitted
1771
+ * BOTH at once; the choice must pick exactly one branch as a
1772
+ * set. */
1773
+ const char* schema =
1774
+ "<element name=\"OMF\" xmlns=\"http://relaxng.org/ns/structure/1.0\">"
1775
+ "<optional><attribute name=\"id\"><data type=\"string\"/></attribute></optional>"
1776
+ "<choice>"
1777
+ "<attribute name=\"dec\"><data type=\"double\"/></attribute>"
1778
+ "<attribute name=\"hex\"><data type=\"hexBinary\"/></attribute>"
1779
+ "</choice></element>";
1780
+ LeptrisRelaxNG rng =
1781
+ leptris_rng_parse(schema, strlen(schema), nullptr);
1782
+ ASSERT_NE(rng, nullptr);
1783
+ LeptrisStatus st = LEPTRIS_OK;
1784
+ struct { const char* doc; int want; const char* why; } cases[] = {
1785
+ {"<OMF dec=\"0.5\"/>", 1, "dec alone: the dec branch"},
1786
+ {"<OMF hex=\"4142\"/>", 1, "hex alone (even-length hex): the hex branch"},
1787
+ {"<OMF dec=\"0.5\" hex=\"A\"/>", 0, /* also: A is invalid hexBinary */
1788
+ "both attributes: two branches at once must reject"},
1789
+ {"<OMF/>", 0, "neither: the choice is required"},
1790
+ {"<OMF id=\"x\" dec=\"0.5\"/>", 1,
1791
+ "an optional attr outside the choice rides along"},
1792
+ };
1793
+ for (auto& c : cases) {
1794
+ LeptrisDocument d = leptris_parse_string(c.doc, strlen(c.doc), &st);
1795
+ ASSERT_NE(d, nullptr) << c.doc;
1796
+ EXPECT_EQ(leptris_rng_validate(rng, d), c.want)
1797
+ << c.why << " — doc: " << c.doc;
1798
+ leptris_document_free(d);
1799
+ }
1800
+ leptris_rng_free(rng);
1801
+ }
1802
+
1803
+ /* ---- leptris#2080: <data> content lexes through the XSD builtins -- */
1804
+
1805
+ TEST(Rng2080Data, Base64BinaryLexes) {
1806
+ /* openmath2.rng's OMB: element content typed base64Binary must
1807
+ * actually lex — "not-base64!!!" validated before the dispatch
1808
+ * reached the engine's builtin lexers. */
1809
+ const char* schema =
1810
+ "<element name=\"OMB\" xmlns=\"http://relaxng.org/ns/structure/1.0\">"
1811
+ "<data type=\"base64Binary\"/></element>";
1812
+ LeptrisRelaxNG rng =
1813
+ leptris_rng_parse(schema, strlen(schema), nullptr);
1814
+ ASSERT_NE(rng, nullptr);
1815
+ LeptrisStatus st = LEPTRIS_OK;
1816
+ struct { const char* doc; int want; } cases[] = {
1817
+ {"<OMB>not-base64!!!</OMB>", 0},
1818
+ {"<OMB>aGVsbG8=</OMB>", 1}, /* "hello" */
1819
+ {"<OMB>AB==</OMB>", 1}, /* padded */
1820
+ {"<OMB>A===</OMB>", 0}, /* over-padded */
1821
+ {"<OMB>AB</OMB>", 1}, /* unpadded 2 bytes */
1822
+ {"<OMB>ABC</OMB>", 1}, /* unpadded 3 chars: 2 bytes */ /* remainder 1 byte */
1823
+ };
1824
+ for (auto& c : cases) {
1825
+ LeptrisDocument d = leptris_parse_string(c.doc, strlen(c.doc), &st);
1826
+ ASSERT_NE(d, nullptr) << c.doc;
1827
+ EXPECT_EQ(leptris_rng_validate(rng, d), c.want)
1828
+ << "doc: " << c.doc;
1829
+ leptris_document_free(d);
1830
+ }
1831
+ leptris_rng_free(rng);
1832
+ }
1833
+
1834
+ TEST(Rng2080Data, HexBinaryLexes) {
1835
+ const char* schema =
1836
+ "<element name=\"H\" xmlns=\"http://relaxng.org/ns/structure/1.0\">"
1837
+ "<data type=\"hexBinary\"/></element>";
1838
+ LeptrisRelaxNG rng =
1839
+ leptris_rng_parse(schema, strlen(schema), nullptr);
1840
+ ASSERT_NE(rng, nullptr);
1841
+ LeptrisStatus st = LEPTRIS_OK;
1842
+ LeptrisDocument d = leptris_parse_string("<H>zz</H>", strlen("<H>zz</H>"), &st);
1843
+ ASSERT_NE(d, nullptr);
1844
+ EXPECT_EQ(leptris_rng_validate(rng, d), 0);
1845
+ leptris_document_free(d);
1846
+ d = leptris_parse_string("<H>0A</H>", strlen("<H>0A</H>"), &st);
1847
+ ASSERT_NE(d, nullptr);
1848
+ EXPECT_EQ(leptris_rng_validate(rng, d), 1);
1849
+ leptris_document_free(d);
1850
+ leptris_rng_free(rng);
1851
+ }
@@ -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.426",
4
+ "version": "1.9.427",
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.426.1
4
+ version: 1.9.427.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -916,8 +916,12 @@ files:
916
916
  - vendor-src/libleptris/test/fuzz/corpus/seed2
917
917
  - vendor-src/libleptris/test/fuzz/corpus/xslt_astcache_uaf_fold.bin
918
918
  - vendor-src/libleptris/test/fuzz/corpus/xslt_astcache_uaf_nightly.bin
919
+ - vendor-src/libleptris/test/fuzz/corpus/xslt_astcache_uaf_session.bin
920
+ - vendor-src/libleptris/test/fuzz/corpus/xslt_carrier_number_uaf.bin
921
+ - vendor-src/libleptris/test/fuzz/corpus/xslt_dispatch_union_dup_hbo.bin
919
922
  - vendor-src/libleptris/test/fuzz/corpus/xslt_dyncall_nontext_callee_segv.xml
920
923
  - vendor-src/libleptris/test/fuzz/corpus/xslt_empty_match_template_leak.xml
924
+ - vendor-src/libleptris/test/fuzz/corpus/xslt_uaf_predicate_layer.bin
921
925
  - vendor-src/libleptris/test/fuzz/corpus/xslt_union_number_head_segv.xml
922
926
  - vendor-src/libleptris/test/fuzz/fuzz_html.c
923
927
  - vendor-src/libleptris/test/fuzz/fuzz_mutate.c