Skip to content

Commit 0a42987

Browse files
authored
Merge pull request #387 from Mingun/seq
Fix errors in sequence deserialization
2 parents 02ba9a8 + 59a5c76 commit 0a42987

File tree

9 files changed

+3465
-56
lines changed

9 files changed

+3465
-56
lines changed

.github/workflows/rust.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ jobs:
4040
env:
4141
LLVM_PROFILE_FILE: coverage/serialize-escape-html-%p-%m.profraw
4242
run: cargo test --features serialize,escape-html
43+
- name: Run tests (all features)
44+
env:
45+
LLVM_PROFILE_FILE: coverage/all-features-%p-%m.profraw
46+
run: cargo test --all-features
4347
- name: Prepare coverage information for upload
4448
if: runner.os == 'Linux'
4549
run: |

Cargo.toml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,52 @@ default = []
4242
## [standard compliant]: https://www.w3.org/TR/xml11/#charencoding
4343
encoding = ["encoding_rs"]
4444

45+
## This feature enables support for deserializing lists where tags are overlapped
46+
## with tags that do not correspond to the list.
47+
##
48+
## When this feature is enabled, the XML:
49+
## ```xml
50+
## <any-name>
51+
## <item/>
52+
## <another-item/>
53+
## <item/>
54+
## <item/>
55+
## </any-name>
56+
## ```
57+
## could be deserialized to a struct:
58+
## ```ignore
59+
## #[derive(Deserialize)]
60+
## #[serde(rename_all = "kebab-case")]
61+
## struct AnyName {
62+
## item: Vec<()>,
63+
## another_item: (),
64+
## }
65+
## ```
66+
##
67+
## When this feature is not enabled (default), only the first element will be
68+
## associated with the field, and the deserialized type will report an error
69+
## (duplicated field) when the deserializer encounters a second `<item/>`.
70+
##
71+
## Note, that enabling this feature can lead to high and even unlimited memory
72+
## consumption, because deserializer should check all events up to the end of a
73+
## container tag (`</any-name>` in that example) to figure out that there are no
74+
## more items for a field. If `</any-name>` or even EOF is not encountered, the
75+
## parsing will never end which can lead to a denial-of-service (DoS) scenario.
76+
##
77+
## Having several lists and overlapped elements for them in XML could also lead
78+
## to quadratic parsing time, because the deserializer must check the list of
79+
## events as many times as the number of sequence fields present in the schema.
80+
##
81+
## To reduce negative consequences, always [limit] the maximum number of events
82+
## that [`Deserializer`] will buffer.
83+
##
84+
## This feature works only with `serialize` feature and has no effect if `serialize`
85+
## is not enabled.
86+
##
87+
## [limit]: crate::de::Deserializer::event_buffer_size
88+
## [`Deserializer`]: crate::de::Deserializer
89+
overlapped-lists = []
90+
4591
## Enables support for [`serde`] serialization and deserialization
4692
serialize = ["serde"]
4793

Changelog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,19 @@
1010

1111
## Unreleased
1212

13+
### New Features
14+
15+
- [#387]: Allow overlapping between elements of sequence and other elements
16+
(using new feature `overlapped-lists`)
17+
1318
### Bug Fixes
1419

1520
- [#9]: Deserialization erroneously was successful in some cases where error is expected.
1621
This broke deserialization of untagged enums which rely on error if variant cannot be parsed
22+
- [#387]: Allow to have an ordinary elements together with a `$value` field
23+
- [#387]: Internal deserializer state can be broken when deserializing a map with
24+
a sequence field (such as `Vec<T>`), where elements of this sequence contains
25+
another sequence. This error affects only users with the `serialize` feature enabled
1726

1827
### Misc Changes
1928

@@ -36,9 +45,11 @@
3645
### New Tests
3746

3847
- [#9]: Added tests for incorrect nested tags in input
48+
- [#387]: Added a bunch of tests for sequences deserialization
3949

4050
[#8]: https://github.com/Mingun/fast-xml/pull/8
4151
[#9]: https://github.com/Mingun/fast-xml/pull/9
52+
[#387]: https://github.com/tafia/quick-xml/pull/387
4253
[#391]: https://github.com/tafia/quick-xml/pull/391
4354

4455
## 0.23.0 -- 2022-05-08

0 commit comments

Comments
 (0)