leptris 1.9.374.0-arm-linux → 1.9.376.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/libleptris.so +0 -0
- data/vendor-src/README.md +1 -1
- data/vendor-src/libleptris/CHANGELOG.md +57 -0
- data/vendor-src/libleptris/CMakeLists.txt +1 -1
- data/vendor-src/libleptris/TODO.SOTA.md +154 -0
- data/vendor-src/libleptris/src/include/leptris.h +10 -0
- data/vendor-src/libleptris/src/leptris/flat/direct_parse.c +126 -0
- data/vendor-src/libleptris/src/leptris/html/html_parse.c +370 -34
- data/vendor-src/libleptris/src/leptris/serialize/serialize.c +15 -43
- data/vendor-src/libleptris/test/html/test_html5lib.cpp +15 -5
- data/vendor-src/libleptris/test/parser/test_encoding.cpp +87 -0
- data/vendor-src/libleptris/test/serializer/test_serialize.cpp +65 -0
- data/vendor-src/libleptris/vcpkg.json +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a1d2a6ae07effed7aa6c2d7404f20d7ec0cc5021ef11a786896aa0c8c0d03b6f
|
|
4
|
+
data.tar.gz: d495291feb1edc3009fbb7534863a4439fc92178bd6e663cd38222a7a52b0b18
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 506eddafab0d94da7b74df620168e5bfbd350eb65110c040aba1aa9cf6d11e67b452801e0216e979a9b9460afad147f0ab1fd04ac606fbb4719826cb8f5a75d8
|
|
7
|
+
data.tar.gz: 9b23d01456189d659c1356c24192013fb4cb99ee3e89dec2556178b94f702c16f3b66458cc881ea2d4ca78705b914e6bc7581a5172e5fbb03ce2d26574866f8f
|
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.
|
|
11
|
+
LIBLEPTRIS_VERSION = "1.9.376"
|
|
12
12
|
# Vendored alongside libleptris for fn:normalize-unicode (TODO
|
|
13
13
|
# .restructure/20): built per platform with a RELOCATABLE @rpath
|
|
14
14
|
# install name, loaded by ffi.rb before libleptris so the
|
data/lib/leptris/version.rb
CHANGED
data/lib/libleptris.so
CHANGED
|
Binary file
|
data/vendor-src/README.md
CHANGED
|
@@ -1,5 +1,62 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [1.9.376] - 2026-10-20
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- **serialize: decoded entity-shaped text is escaped
|
|
8
|
+
unconditionally (leptris-ruby#515, PR #1793).** Parse expands
|
|
9
|
+
entities into text (named references that survive under
|
|
10
|
+
`KEEP_ENTITY_REFS` become `ENTITY_REF` nodes), but both text
|
|
11
|
+
emitters kept an entity lookahead that re-emitted decoded data
|
|
12
|
+
verbatim: `A` reparsed as `A`, and `<UK>` minted a
|
|
13
|
+
`<UK>` element that swallowed siblings. Every `&` in text is now
|
|
14
|
+
escaped; `ENTITY_REF` nodes still serialize as markup.
|
|
15
|
+
- **parse: strict loads validate the effective encoding
|
|
16
|
+
(leptris-ruby#514, PR #1793).** Non-RECOVER parses reject
|
|
17
|
+
invalid UTF-8 under XML 1.0 §4.3.3 (RFC 3629 strictness:
|
|
18
|
+
overlongs, surrogates, >U+10FFFF, truncation are fatal), for
|
|
19
|
+
documents that are UTF-8 by declaration or default. A declared
|
|
20
|
+
non-UTF-8 encoding is exempt (legacy encodings still transcode
|
|
21
|
+
through the iconv lane), and RECOVER keeps the #1660
|
|
22
|
+
best-effort-tree contract. The ASCII fast path scans
|
|
23
|
+
word-at-a-time (~14 GB/s, ~0.2% of a full parse).
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- **html: verdict parity 1446 to 1508 of 1555 (PR #1794).** Seven
|
|
28
|
+
emission slices, each grounded in html5lib's source and gated by
|
|
29
|
+
the #1771 corpus harness with zero want=clean regressions:
|
|
30
|
+
depth-0 stray raw-text end tags (`</script>`, `</style>`, …);
|
|
31
|
+
later `<html>` tokens (non-html-root); the end-tag-too-early
|
|
32
|
+
family (heading mismatch, implied-end crossings, and the same
|
|
33
|
+
rule on li/dd/dt/p implied closes); after-body/frameset phase
|
|
34
|
+
codes; InBody frameset, duplicate body/head, and AfterHead
|
|
35
|
+
out-of-my-head tags; select/table/foreign codes
|
|
36
|
+
(unexpected-input-in-select, hidden-input-in-table,
|
|
37
|
+
unexpected-html-element-in-foreign-content); and tokenizer
|
|
38
|
+
need-space-after-doctype. Tree parity stays 1555/1555; the
|
|
39
|
+
verdict floor rose from 1409 to 1508.
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
## [1.9.375] - 2026-10-20
|
|
44
|
+
|
|
45
|
+
### Added
|
|
46
|
+
|
|
47
|
+
- **html: the #1771 verdict-parity emission slices (PRs #1788,
|
|
48
|
+
#1789, #1790, #1791) — parity 1394 to 1423 of 1555.** The EOF
|
|
49
|
+
closing-tag verdict now implements html5lib's InBody processEOF
|
|
50
|
+
allowed-set exactly (zero false positives — the lint's first
|
|
51
|
+
requirement); the in-select drop sites report
|
|
52
|
+
unexpected-start/end-tag-in-select and unexpected-select-in-
|
|
53
|
+
select; the foster branch reports foster-parenting-character/
|
|
54
|
+
-start-tag by node kind; unknown-doctype follows html5lib's
|
|
55
|
+
BeforeHtml processDoctype (name/public/system shape). Trees
|
|
56
|
+
byte-identical throughout (1555/1555); full suite green at
|
|
57
|
+
every step.
|
|
58
|
+
|
|
59
|
+
|
|
3
60
|
## [1.9.374] - 2026-10-19
|
|
4
61
|
|
|
5
62
|
### Fixed
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# TODO.SOTA — the vision of done
|
|
2
|
+
|
|
3
|
+
The audit underneath this board: an XML stack is an **epistemic
|
|
4
|
+
instrument** — it decides what a document means. Its purpose is
|
|
5
|
+
trustworthy interpretation, made affordable everywhere. SOTA is
|
|
6
|
+
therefore not a feeling but four provable claims, each with a
|
|
7
|
+
measurement command whose output is the verdict:
|
|
8
|
+
|
|
9
|
+
1. **Conformance** — we interpret every document the way the
|
|
10
|
+
specifications (and the reference suites) say. *Proof: zero reds
|
|
11
|
+
on every adopted suite.*
|
|
12
|
+
2. **Performance** — correctness is free; we are faster than every
|
|
13
|
+
incumbent on every published shape. *Proof: ≥1.00x on every row,
|
|
14
|
+
interleaved medians.*
|
|
15
|
+
3. **Safety** — trust is auditable: memory-safe under sanitizers,
|
|
16
|
+
fuzz-clean, reproducibly built. *Proof: clean lanes + per-release
|
|
17
|
+
build manifests.*
|
|
18
|
+
4. **Universality** — the same semantics in every language; a
|
|
19
|
+
document means the same thing through every runtime. *Proof: a
|
|
20
|
+
cross-runtime differential corpus, byte-identical.*
|
|
21
|
+
|
|
22
|
+
Everything below is the task board for those four proofs. Every row
|
|
23
|
+
ends with a dated measurement; the scoreboard lives in
|
|
24
|
+
docs/MISSION-PLAN.md and is updated at every release.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Gate A — Conformance: zero reds everywhere
|
|
29
|
+
|
|
30
|
+
### A1 WHATWG verdict parity: 1394/1555 → 1555/1555
|
|
31
|
+
The remaining 161 verdict cases + ~270 code-set divergences
|
|
32
|
+
(html5lib-verdict-redlist.txt). Ground every slice in html5lib's
|
|
33
|
+
actual source (~/src/external/html5lib):
|
|
34
|
+
- [ ] escaped-state EOF codes (`unexpected-eof-in-text-mode`,
|
|
35
|
+
`eof-in-script-in-script`) — the script-data state machine's
|
|
36
|
+
EOF classification
|
|
37
|
+
- [ ] the after-body EOF phase rule (tests1:34 class; the exact
|
|
38
|
+
phaseAtBody.eof semantics)
|
|
39
|
+
- [ ] in-body `unexpected-start-tag` family (body/frameset/form
|
|
40
|
+
starts; the startTagBody/Forms/Frameset error sites)
|
|
41
|
+
- [ ] `unexpected-end-tag` family (p-in-button-scope synthesis,
|
|
42
|
+
form pointer, li/dd/dt scope, endTagOther walk)
|
|
43
|
+
- [ ] foster-parenting sites (start-tag/character/character-in-table)
|
|
44
|
+
- [ ] adoption-agency codes (`adoption-agency-1.3` et al.)
|
|
45
|
+
- [ ] in-table voodoo (`*-implies-table-voodoo`, cells, eof-in-table)
|
|
46
|
+
- [ ] unknown-doctype / unexpected-char-in-doctype (doctype
|
|
47
|
+
tokenization §13.2.5.28+)
|
|
48
|
+
- [ ] non-html-root, select-mode codes, heading/edge shapes
|
|
49
|
+
|
|
50
|
+
### A2 QT3 / XQuery 3.1: zero unexplained pins
|
|
51
|
+
- [ ] re-pin fresh (the ~41–99 slice figures are dated)
|
|
52
|
+
- [ ] every remaining pin gets a disposition file or a fix
|
|
53
|
+
- [ ] ctor node-yield family: owned_docs transfer completion
|
|
54
|
+
|
|
55
|
+
### A3 XSD conformance lane: suite-complete
|
|
56
|
+
- [ ] the lane's own queue (769→795 → its ceiling) to zero
|
|
57
|
+
|
|
58
|
+
### A4 DTD phase 8 (TODO 91)
|
|
59
|
+
- [ ] ENTITY/ENTITIES attribute resolution
|
|
60
|
+
- [ ] parameter entities, choice-model backtracking
|
|
61
|
+
|
|
62
|
+
### A5 XInclude completeness (TODO 92)
|
|
63
|
+
- [ ] `parse="xml"` (ownership-transfer splice exists — wire it)
|
|
64
|
+
- [ ] xpointer
|
|
65
|
+
|
|
66
|
+
### A6 The universality proof (differential corpus)
|
|
67
|
+
- [ ] one curated corpus (the html5lib + QT3-winner + metanorma
|
|
68
|
+
sample set) run through ruby/py/ts/rs bindings
|
|
69
|
+
- [ ] byte-identical outputs asserted in CI (the "one engine, same
|
|
70
|
+
numbers everywhere" proof)
|
|
71
|
+
|
|
72
|
+
### A7 Maintain (already green; keep gated)
|
|
73
|
+
- [ ] XML 1.0, XPath 438/438, libxslt 205/205, XsltFull,
|
|
74
|
+
C14N, RelaxNG, SAX records lane
|
|
75
|
+
|
|
76
|
+
## Gate B — Performance: every published row ≥1.00x
|
|
77
|
+
|
|
78
|
+
### B1 build row: ~2.9x → ≤1.0x (the #242 campaign)
|
|
79
|
+
Harness: wt/460-harness/build_bench.rb. Decomposition on record.
|
|
80
|
+
- [ ] per-element object budget: one Ruby object per created node
|
|
81
|
+
(drop the shell entirely post-create-priming; the mint cache
|
|
82
|
+
insert policy; the context registration)
|
|
83
|
+
- [ ] the root `to_binding` bridge (set_root path)
|
|
84
|
+
- [ ] `[]=` / `text=` write faces (nn_set_attribute pattern applied
|
|
85
|
+
to text writes; one C frame per write)
|
|
86
|
+
|
|
87
|
+
### B2 walk row: 0.88x → much faster
|
|
88
|
+
Per-face reads already 3–5x ahead; the harness floor is shared
|
|
89
|
+
scaffolding. Memo law holds (dropping @children memo = 2x GC).
|
|
90
|
+
- [ ] hot-path audit of NodeSet#each / block dispatch
|
|
91
|
+
- [ ] publish the per-face table (the honest much-faster story)
|
|
92
|
+
|
|
93
|
+
### B3 whole-pipeline rows (new, published)
|
|
94
|
+
- [ ] parse→query→serialize pipeline row vs nokogiri/libxml2
|
|
95
|
+
- [ ] build→transform (XSLT) pipeline row
|
|
96
|
+
- [ ] both to serialbench as the public scoreboard
|
|
97
|
+
|
|
98
|
+
### B4 durability
|
|
99
|
+
- [ ] CI perf regression gates on the chokepoints (parse, walk,
|
|
100
|
+
build, serialize medians, fail on >5% regression)
|
|
101
|
+
|
|
102
|
+
### B5 remaining red rows
|
|
103
|
+
- [ ] pugixml lane-18 append/attr-parse (2.0x/5.9x; hash prefilter)
|
|
104
|
+
- [ ] zero-copy text lever (#1218) — adopt if it wins any row
|
|
105
|
+
|
|
106
|
+
## Gate C — Safety: trust is auditable
|
|
107
|
+
|
|
108
|
+
- [ ] C1 structure-aware fuzzing: grammar-aware corpora for
|
|
109
|
+
XML/XPath/XSLT/HTML (grow beyond the three libFuzzer harnesses;
|
|
110
|
+
corpus commit + crash-triage SLA)
|
|
111
|
+
- [ ] C2 sanitizer lanes over the risk families: records-drain,
|
|
112
|
+
borrowed-slice + pool-recycle (the #506 class), iterparse
|
|
113
|
+
keepalive — ASAN/UBSAN now, add TSAN (batch/worker surfaces)
|
|
114
|
+
- [ ] C3 reproducible builds everywhere: darwin toolchain pin done
|
|
115
|
+
(ruby#512) — extend to linux/windows legs; publish a per-
|
|
116
|
+
release build manifest (engine + binding hashes per platform)
|
|
117
|
+
- [ ] C4 security.md: advisory channel, CVE-response process,
|
|
118
|
+
dependency-free attestation
|
|
119
|
+
- [ ] C5 the memory story documented: pool arena model, leak gates,
|
|
120
|
+
the borrowed-slice lifetime contract
|
|
121
|
+
|
|
122
|
+
## Gate D — Universality: same semantics everywhere
|
|
123
|
+
|
|
124
|
+
- [ ] D1 leptris-descriptor published (crates.io; feat/294 branch
|
|
125
|
+
lands), rides lockstep
|
|
126
|
+
- [ ] D2 system packaging: homebrew, conan, deb (apt repo)
|
|
127
|
+
- [ ] D3 cross-runtime differential CI (= A6, wired)
|
|
128
|
+
- [ ] D4 libxml2→libleptris migration guide (docs/guide/) + the
|
|
129
|
+
nokogiri-compat surface documented
|
|
130
|
+
|
|
131
|
+
## Gate E — 1.0 (the seal)
|
|
132
|
+
|
|
133
|
+
- [ ] E1 Gate A + B report zero reds (dated scoreboard)
|
|
134
|
+
- [ ] E2 semver freeze, ABI stability policy, platform matrix doc
|
|
135
|
+
- [ ] E3 v1.0.0 through the release workflow — never tagged by hand
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Invariants (the laws the board executes inside)
|
|
140
|
+
|
|
141
|
+
- Falsifiability: red-first specs; both-directions measurement.
|
|
142
|
+
- Lockstep + TAG-RACE; the release workflow owns versions and tags.
|
|
143
|
+
- One branch/PR per item; worktrees at wt/; never commit on main;
|
|
144
|
+
never `git add -A`; verify the branch before every commit.
|
|
145
|
+
- Aliases before shims: unshadowed C faces upstream; consumers
|
|
146
|
+
face-probe and plain-dispatch.
|
|
147
|
+
- Suites over opinions; the corpus is the reference.
|
|
148
|
+
|
|
149
|
+
## Definition of done
|
|
150
|
+
|
|
151
|
+
Every checkbox above carries a dated measurement command and its
|
|
152
|
+
recorded result; docs/MISSION-PLAN.md's scoreboard shows Gate A and
|
|
153
|
+
Gate B at zero reds; v1.0.0 is tagged. That day, the libxml2 era is
|
|
154
|
+
over wherever this engine ships.
|
|
@@ -838,6 +838,11 @@ LEPTRIS_API LeptrisStatus leptris_document_set_root_ex(
|
|
|
838
838
|
/**
|
|
839
839
|
* Parse XML string into document
|
|
840
840
|
*
|
|
841
|
+
* Encoding: the input must be valid in its effective encoding. With
|
|
842
|
+
* no XML declaration (or a UTF-8/US-ASCII one) that is UTF-8 (XML
|
|
843
|
+
* 1.0 §4.3.3) and invalid byte sequences are a fatal load error. A
|
|
844
|
+
* declared legacy encoding is transcoded to UTF-8 before parsing.
|
|
845
|
+
*
|
|
841
846
|
* @param xml XML string (must be valid UTF-8)
|
|
842
847
|
* @param length Length of XML string in bytes
|
|
843
848
|
* @param status Output status code (can be NULL)
|
|
@@ -979,6 +984,11 @@ LEPTRIS_API int leptris_rng_error_line(LeptrisRelaxNG rng, size_t i);
|
|
|
979
984
|
LEPTRIS_API int leptris_rng_error_column(LeptrisRelaxNG rng, size_t i);
|
|
980
985
|
|
|
981
986
|
|
|
987
|
+
/* Parse with explicit flags. Strict (non-RECOVER) parses validate
|
|
988
|
+
* the input against its effective encoding (see leptris_parse_string);
|
|
989
|
+
* RECOVER keeps the best-effort #1660 contract and skips the fatal
|
|
990
|
+
* encoding check. A declared non-UTF-8 encoding is exempt from UTF-8
|
|
991
|
+
* validation and passes through raw in this lane. */
|
|
982
992
|
LEPTRIS_API LeptrisDocument leptris_parse_string_flags(const char* xml,
|
|
983
993
|
size_t length,
|
|
984
994
|
LeptrisParseFlags flags,
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
#include <string.h>
|
|
44
44
|
#include <stdlib.h>
|
|
45
45
|
#include <stdio.h>
|
|
46
|
+
#include <stdint.h>
|
|
46
47
|
|
|
47
48
|
/* File-scope externs: engine config TLS defined in core.c (declared
|
|
48
49
|
* in leptris_internal.h; this TU reads it without the umbrella) and
|
|
@@ -3415,6 +3416,123 @@ static struct leptris_document* dp_il_try(const char* xml, size_t len,
|
|
|
3415
3416
|
return d;
|
|
3416
3417
|
}
|
|
3417
3418
|
|
|
3419
|
+
/* ---- Load-time encoding validation (leptris-ruby#514) ----
|
|
3420
|
+
*
|
|
3421
|
+
* XML 1.0 §4.3.3: a document without a declaration is UTF-8; a
|
|
3422
|
+
* declared non-UTF-8 encoding is exempt (its bytes are legitimately
|
|
3423
|
+
* not UTF-8 — leptris_parse_string transcodes declared legacy
|
|
3424
|
+
* encodings through iconv before they reach this funnel). Structural
|
|
3425
|
+
* UTF-8 (RFC 3629) is strict: overlongs, surrogates, >U+10FFFF and
|
|
3426
|
+
* truncated sequences are fatal, matching libxml2's load-time
|
|
3427
|
+
* "Invalid bytes in character encoding". */
|
|
3428
|
+
|
|
3429
|
+
static int dp_ascii_case_eq(const char* a, const char* b, size_t n) {
|
|
3430
|
+
for (size_t i = 0; i < n; i++) {
|
|
3431
|
+
char x = a[i];
|
|
3432
|
+
char y = b[i];
|
|
3433
|
+
if (x >= 'A' && x <= 'Z') x += 32;
|
|
3434
|
+
if (y >= 'A' && y <= 'Z') y += 32;
|
|
3435
|
+
if (x != y) return 0;
|
|
3436
|
+
}
|
|
3437
|
+
return 1;
|
|
3438
|
+
}
|
|
3439
|
+
|
|
3440
|
+
/* 1 when the XML declaration names an encoding other than UTF-8 /
|
|
3441
|
+
* US-ASCII. No (or unreadable) declaration -> 0, the UTF-8 default. */
|
|
3442
|
+
static int dp_declares_non_utf8(const char* s, size_t len) {
|
|
3443
|
+
size_t i = 0;
|
|
3444
|
+
if (len >= 3 && (unsigned char)s[0] == 0xEF &&
|
|
3445
|
+
(unsigned char)s[1] == 0xBB && (unsigned char)s[2] == 0xBF) {
|
|
3446
|
+
i = 3;
|
|
3447
|
+
}
|
|
3448
|
+
if (len - i < 5 || memcmp(s + i, "<?xml", 5) != 0) return 0;
|
|
3449
|
+
if (len - i > 5) {
|
|
3450
|
+
char c = s[i + 5];
|
|
3451
|
+
if (c != ' ' && c != '\t' && c != '\r' && c != '\n' && c != '?')
|
|
3452
|
+
return 0;
|
|
3453
|
+
}
|
|
3454
|
+
size_t j = i + 5;
|
|
3455
|
+
size_t end = j;
|
|
3456
|
+
while (end + 1 < len && !(s[end] == '?' && s[end + 1] == '>')) end++;
|
|
3457
|
+
if (end + 1 >= len) return 0;
|
|
3458
|
+
while (j < end) {
|
|
3459
|
+
if (end - j >= 8 && memcmp(s + j, "encoding", 8) == 0 &&
|
|
3460
|
+
(j == i + 5 || s[j - 1] == ' ' || s[j - 1] == '\t' ||
|
|
3461
|
+
s[j - 1] == '\r' || s[j - 1] == '\n')) {
|
|
3462
|
+
size_t k = j + 8;
|
|
3463
|
+
while (k < end && (s[k] == ' ' || s[k] == '\t' ||
|
|
3464
|
+
s[k] == '\r' || s[k] == '\n')) k++;
|
|
3465
|
+
if (k < end && s[k] == '=') {
|
|
3466
|
+
k++;
|
|
3467
|
+
while (k < end && (s[k] == ' ' || s[k] == '\t' ||
|
|
3468
|
+
s[k] == '\r' || s[k] == '\n')) k++;
|
|
3469
|
+
if (k < end && (s[k] == '"' || s[k] == '\'')) {
|
|
3470
|
+
char q = s[k++];
|
|
3471
|
+
size_t v = k;
|
|
3472
|
+
while (k < end && s[k] != q) k++;
|
|
3473
|
+
size_t vl = k - v;
|
|
3474
|
+
if (vl == 5 && dp_ascii_case_eq(s + v, "UTF-8", 5)) return 0;
|
|
3475
|
+
if (vl == 4 && dp_ascii_case_eq(s + v, "UTF8", 4)) return 0;
|
|
3476
|
+
if (vl == 8 && dp_ascii_case_eq(s + v, "US-ASCII", 8))
|
|
3477
|
+
return 0;
|
|
3478
|
+
return 1;
|
|
3479
|
+
}
|
|
3480
|
+
}
|
|
3481
|
+
}
|
|
3482
|
+
j++;
|
|
3483
|
+
}
|
|
3484
|
+
return 0;
|
|
3485
|
+
}
|
|
3486
|
+
|
|
3487
|
+
static int dp_utf8_valid(const char* s, size_t len) {
|
|
3488
|
+
const unsigned char* p = (const unsigned char*)s;
|
|
3489
|
+
size_t i = 0;
|
|
3490
|
+
/* ASCII fast path: 8 bytes per iteration. The DFA below runs
|
|
3491
|
+
* only when a high byte is present; ordinary documents pay one
|
|
3492
|
+
* memory-bandwidth pass. */
|
|
3493
|
+
while (i + 8 <= len) {
|
|
3494
|
+
uint64_t w;
|
|
3495
|
+
memcpy(&w, p + i, 8);
|
|
3496
|
+
if (w & UINT64_C(0x8080808080808080)) break;
|
|
3497
|
+
i += 8;
|
|
3498
|
+
}
|
|
3499
|
+
while (i < len && p[i] < 0x80) i++;
|
|
3500
|
+
while (i < len) {
|
|
3501
|
+
unsigned c = p[i];
|
|
3502
|
+
if (c < 0x80) {
|
|
3503
|
+
i++;
|
|
3504
|
+
continue;
|
|
3505
|
+
}
|
|
3506
|
+
size_t n;
|
|
3507
|
+
unsigned lo = 0x80;
|
|
3508
|
+
unsigned hi = 0xBF;
|
|
3509
|
+
if (c >= 0xC2 && c <= 0xDF) {
|
|
3510
|
+
n = 1;
|
|
3511
|
+
} else if (c >= 0xE0 && c <= 0xEF) {
|
|
3512
|
+
n = 2;
|
|
3513
|
+
if (c == 0xE0) lo = 0xA0;
|
|
3514
|
+
else if (c == 0xED) hi = 0x9F;
|
|
3515
|
+
} else if (c >= 0xF0 && c <= 0xF4) {
|
|
3516
|
+
n = 3;
|
|
3517
|
+
if (c == 0xF0) lo = 0x90;
|
|
3518
|
+
else if (c == 0xF4) hi = 0x8F;
|
|
3519
|
+
} else {
|
|
3520
|
+
return 0;
|
|
3521
|
+
}
|
|
3522
|
+
if (len - i <= n) return 0;
|
|
3523
|
+
if (p[i + 1] < lo || p[i + 1] > hi) return 0;
|
|
3524
|
+
for (size_t k = 2; k <= n; k++) {
|
|
3525
|
+
if (p[i + k] < 0x80 || p[i + k] > 0xBF) return 0;
|
|
3526
|
+
}
|
|
3527
|
+
i += n + 1;
|
|
3528
|
+
}
|
|
3529
|
+
return 1;
|
|
3530
|
+
}
|
|
3531
|
+
|
|
3532
|
+
static int dp_input_encoding_ok(const char* s, size_t len) {
|
|
3533
|
+
return dp_declares_non_utf8(s, len) || dp_utf8_valid(s, len);
|
|
3534
|
+
}
|
|
3535
|
+
|
|
3418
3536
|
/* Public: copy the input then parse (standard path).
|
|
3419
3537
|
*
|
|
3420
3538
|
* The copy and the arena-sizing pre-scan are ONE fused SIMD pass
|
|
@@ -3424,6 +3542,7 @@ static struct leptris_document* dp_il_try(const char* xml, size_t len,
|
|
|
3424
3542
|
* arena holds only nodes and strings. */
|
|
3425
3543
|
struct leptris_document* direct_parse(const char* xml, size_t len) {
|
|
3426
3544
|
if (!xml || len == 0) return NULL;
|
|
3545
|
+
if (!dp_input_encoding_ok(xml, len)) return NULL;
|
|
3427
3546
|
{
|
|
3428
3547
|
struct leptris_document* d = dp_il_try(xml, len, 0, 0, 0);
|
|
3429
3548
|
if (d) return d;
|
|
@@ -3435,6 +3554,12 @@ struct leptris_document* direct_parse(const char* xml, size_t len) {
|
|
|
3435
3554
|
struct leptris_document* direct_parse_flags(const char* xml, size_t len,
|
|
3436
3555
|
unsigned parse_flags) {
|
|
3437
3556
|
if (!xml || len == 0) return NULL;
|
|
3557
|
+
/* RECOVER keeps the #1660 best-effort contract (never NULL for
|
|
3558
|
+
* malformed input); the fatal encoding check is strict-lane. */
|
|
3559
|
+
if (!(parse_flags & LEPTRIS_PARSE_RECOVER) &&
|
|
3560
|
+
!dp_input_encoding_ok(xml, len)) {
|
|
3561
|
+
return NULL;
|
|
3562
|
+
}
|
|
3438
3563
|
/* The interleaved lane has no recovery support (#1660) — RECOVER
|
|
3439
3564
|
* parses take the default lane. */
|
|
3440
3565
|
if (!(parse_flags & LEPTRIS_PARSE_RECOVER)) {
|
|
@@ -3462,6 +3587,7 @@ struct leptris_document* direct_parse_flags(const char* xml, size_t len,
|
|
|
3462
3587
|
/* Public: parse a caller-owned writable buffer without copying. */
|
|
3463
3588
|
struct leptris_document* direct_parse_inplace(char* buf, size_t len) {
|
|
3464
3589
|
if (!buf || len == 0) return NULL;
|
|
3590
|
+
if (!dp_input_encoding_ok(buf, len)) return NULL;
|
|
3465
3591
|
buf[len] = '\0'; /* Ensure NUL termination */
|
|
3466
3592
|
return direct_parse_internal(buf, len, 0, 0, 0, 0, 0, 0);
|
|
3467
3593
|
}
|