0
0
mirror of https://github.com/zeux/pugixml.git synced 2024-12-26 21:04:25 +08:00

549 Commits

Author SHA1 Message Date
Arseny Kapoulkine
5c4225b5c9 tests: Fix wchar_t build 2021-05-11 23:22:13 -07:00
Arseny Kapoulkine
8cece4b9fe Fix a bug in move construction when move source is empty
Previously when copying the allocator state we would copy an incorrect
root pointer into the document's current state; while this had a minimal
impact on the allocation state due to the fact that any new allocation
would need to create a new page, this used a potentially stale field of
the moved document when setting up new pages, which could create issues
in future uses of the pages.

This change fixes the core problem and also removes the use of the
_root->allocator from allocate_page since it's not clear why we need it
there in the first place.
2021-05-11 22:53:54 -07:00
Arseny Kapoulkine
56c9afa7c8 XPath: Improve recursion limit for deep chains of //
Since foo//bar//baz adds two nodes for each //, we need to increment the
depth by 2 on each iteration to limit the AST correctly.

Fixes the stack overflow found by cluster-fuzz (I suspect the issue
there is a bit deeper, but this part is definitely a bug and as such I'd
rather wait for the next test case for now).
2021-05-11 22:27:53 -07:00
Arseny Kapoulkine
70bd6a6b0a Update version to 1.11 and update documentation 2020-11-25 10:18:42 -08:00
Arseny Kapoulkine
8afc1239a3 tests: Fix test fallout for MSVC6
One more XPath test falls prey to MSVC6 NaN comparison codegen issues.
2020-11-25 09:48:19 -08:00
Arseny Kapoulkine
8e5b8e0f46 XPath: Fix stack overflow in functions with long argument lists
Function call arguments are stored in a list which is processed
recursively during optimize(). We now limit the depth of this construct
as well to make sure optimize() doesn't run out of stack space.
2020-09-11 09:50:41 -07:00
Arseny Kapoulkine
20aef1cd4b Fix stack overflow in tests on MSVC x64
The default stack on MSVC/x64/debug is sufficient for 1692 nested
invocations only, whereas on clang/linux it's ~8K...

For now set the limit to be conservative.
2020-09-10 09:11:46 -07:00
Arseny Kapoulkine
c7090e6c33 Fix tests in wchar mode 2020-09-10 01:07:48 -07:00
Arseny Kapoulkine
1f84db837b XPath: Restrict AST depth to prevent stack overflow
XPath parser and execution engine isn't stackless; the depth of the
query controls the amount of C stack space required.

This change instruments places in the parser where the control flow can
recurse, requiring too much C stack space to produce an AST, or where a
stackless parse is used to produce arbitrarily deep AST which will
create issues for downstream processing.

As a result XPath parser should now be fuzz safe for malicious inputs.
2020-09-10 00:55:26 -07:00
Arseny Kapoulkine
85a39b955d tests: Add a dedicated test for XPath variable conversion
This makes sure all conversions work as expected (note that no type can
be converted to node set so we don't check that).
2020-02-01 07:44:14 -08:00
Tuan Anh Tran
b9b2aeecaf Custom precision (#300)
Fixes #285
2019-09-22 08:42:41 -07:00
Arseny Kapoulkine
6202519ca6 tests: Add memory safety tests for remove_children/attributes
The newly added tests make sure that during node/attribute destruction
we deallocate a few memory pages; this makes sure that we don't read
node data after it's being destroyed.

Also clean up formatting/style in the remove_* implementation a bit.
2019-09-17 20:34:40 -07:00
Tuan Anh Tran
fd7326fb91 feat: add remove_attributes() and remove_children() (#296)
These functions remove all attributes / child nodes in bulk which is faster than removing them one at a time.
2019-09-17 20:18:41 -07:00
Arseny Kapoulkine
c6607740a0 Never escape > in attribute values
According to XML spec, > sometimes needs to be escaped in PCDATA (when
it occurs as a ]]> pattern), but it doesn't need to be escaped in
attribute values.

Contributes to #272.
2019-09-11 21:35:03 -07:00
Arseny Kapoulkine
946de603b1 Don't escape attribute quotation symbol
When using double quotes for attributes, we don't need to escape '; when
using single quotes, we don't need to escape ".

This changes behavior to match 1.9 by default (where we don't escape ').

Contributes to #272.
2019-09-11 21:27:20 -07:00
Arseny Kapoulkine
44e4d7e40b Update version to 1.10
Note: this chang also updates PUGIXML_VERSION macro to allow for
double-digit minor versions; this preserves the continuity of versions
so PUGIXML_VERSION >= 190 will still work.
2019-09-11 21:09:50 -07:00
Joel Andres Granados
84e322738b Update nuget creation to VS2019 (#291)
Create visual studio projects that are vs2019 compliant.
* nuget_build.ps1 :
Introduce a new argument that will define how we implement the nuget
build. For now we accept 201{9,7.5.3} as possible argument values.

* pugixml_vs2019{,_static}.vcxproj :
Add two visual studio projects that build pugi with the latest SDK and
build tools

* appveyor.yml
- Add Visual Studio 2019 to build targets
- Add Visual Studio 201{9,3,5} to build_scripts. And call
  nuget_build.ps1 with a new argument.
- Add Visual Studio 2019 to the test_scripts.
2019-09-09 07:37:29 -07:00
Wolfgang Stöggl
fdf0295753 Fix minor typos (#286)
- Typos were found by codespell v1.15.0
2019-08-21 07:46:11 -07:00
Arseny Kapoulkine
a556845555 tests: Work around test warnings in clang-7
Self-assignment generates a Wself-assign-overloaded warning.
2019-08-21 07:45:27 -07:00
m-naumann
5a867cb1e3 Add support for using single quotes to enclose attribute values
This change adds format_attribute_single_quote flag that uses single quotes (`'`) instead of double quotes (`"`) for formatting attribute values.

Internal quotation marks are escaped using `"` and `'`.
2019-06-18 19:51:10 -07:00
denchat
86e0fe1980
Fix forgotten indentation 2019-06-10 00:35:17 +07:00
denchat
1312a46d91
std::random_shuffle is removed in current standard
use <random> 's generator and std::shuffle instead
2019-06-10 00:14:21 +07:00
Arseny Kapoulkine
8bf806c035 tests: Move control char tests to test_write.cpp
Also fix code style.
2019-03-09 06:58:07 -08:00
Yan Pas
138976fd95 unit test and doc 2019-03-08 19:17:19 +03:00
Arseny Kapoulkine
12e8b699ce tests: Expand out-of-memory union tests
We now have two tests: one tests behavior when we run out of space when
appending the node set (in which case the append fails), another one
tests behavior when we run out of space when filtering the node set (in
which case the set still contains redundant data).
2019-02-26 23:57:58 -08:00
Arseny Kapoulkine
c55ea3bc1e XPath: Make remove_duplicates generate stable order
Given an unsorted sequence, remove_duplicates would sort it using the
pointer value of attributes/nodes and then remove consecutive
duplicates.

This was problematic because it meant that the result of XPath queries
was dependent on the memory allocation pattern. While it's technically
incorrect to rely on the order, this results in easy to miss bugs.

This is particularly common when XPath queries use union operators -
although we also will call remove_duplicates in other cases.

This change reworks the code to use a hash set instead, using the same
hash function we use for compact storage. To make sure it performs well,
we allocate enough buckets for count * 1.5 (assuming all elements are
unique); since each bucket is a single pointer unlike xpath_node which
is two pointers, we need somewhere between size * 0.75 and size * 1.5
temporary storage.

The resulting filtering is stable - we remove elements that we have seen
before but we don't change the order - and is actually significantly
faster than sorting was.

With a large union operation, before this change it took ~56 ms per 100
query invocations to remove duplicates, and after this change it takes
~20ms.

Fixes #254.
2019-02-26 23:57:58 -08:00
Arseny Kapoulkine
930a701f1f tests: Disable flaky test
This test is very sensitive to the particular implementation of union
aggregation; for now lets disable this.

We need a more robust way to test union allocation failures.
2019-02-26 22:15:34 -08:00
Arseny Kapoulkine
7664bbf9af tests: Only use load_file_special_folder test on macOS
The behavior on Linux is very different between kernel versions, and it
triggers an unexpected OOM during sanitizer runs because somehow the
size is reported to be LONG_MAX. It's not clear that it helps us cover
any paths we don't cover otherwise - it would be nice to be able to test
failing to load a multi-gigabyte file on a 32-bit system, but we can't
do this easily atm anyway.
2018-11-27 08:07:31 -08:00
Arseny Kapoulkine
f9a2a7d19e Fix Wdouble-promotion warnings
We had a few places in test code and library source where we used an
implicit float->double cast; while it should preserve the value exactly,
gcc/clang implement this warning to make sure uses of double are intentional.

This change also adds the warning to Makefile to make sure we don't
regress on this warning.

Fixes #243.
2018-11-23 23:39:22 -08:00
Arseny Kapoulkine
aac75cd299 Escape TAB character in attribute values with &#09;
This change modifies the table entries for ctx_special_attr to treat TAB
character as special, which makes the output code escape it.

Before this change, trying to use TAB in an attribute value would output
it verbatim; during subsequent parsing, pugixml - and other compliant
parsers - would apply attribute-value normalization, turning the TAB
into a space and losing the original value.

Using &#09; fixes this; if an input document has &#09; in an attribute
value, that gets unescaped into \t during parsing and escaped back into
&#09; during output, which means we can now roundtrip values like this.

Fixes #242.
2018-11-19 22:26:21 -08:00
Arseny Kapoulkine
1a96777b11 tests: Fix XPath denorm tests on Intel compiler
Intel compiler by default sets flush-to-zero flags which causes our
denorm test to produce 0.0. So make sure that denorms work on FPU before
testing the string output.

Fixes #218.
2018-08-13 22:06:57 -07:00
Arseny Kapoulkine
6b9c07e6ed tests: Allow document_load_file_special_folder to load empty document
On some Debian systems it looks like we *can* open the current folder as
a file and read its contents, but parsing the result produces an empty
document. We now handle this case as well.

Fixes #225.
2018-07-30 07:32:09 -07:00
Arseny Kapoulkine
8436f2a69b tests: Fix PUGIXML_COMPACT build on some platforms
We need bad_alloc that lives in <new>, not <exception>.
2018-04-04 07:53:16 -07:00
Arseny Kapoulkine
474a4a3f73 tests: Fix PUGIXML_NO_XPATH,PUGIXML_COMPACT build
pugixml.hpp wasn't including the <exception> header in this build but
test code needed it.
2018-04-03 21:56:09 -07:00
Arseny Kapoulkine
5f4afe3bd2 tests: Fix PUGIXML_NO_XPATH build 2018-04-03 21:51:41 -07:00
Arseny Kapoulkine
62728d9c2e tests: Fix PUGIXML_NO_EXCEPTIONS tests 2018-04-02 21:51:04 -07:00
Arseny Kapoulkine
0c74e117b8 Update version to 1.9 2018-04-02 21:46:14 -07:00
Arseny Kapoulkine
a32585286a tests: Fix PUGIXML_NO_STL build 2018-04-02 21:33:03 -07:00
Arseny Kapoulkine
fe7b837868 tests: Fix PUGIXML_COMPACT+PUGIXML_WCHAR_MODE tests
Several tests got the buffer size wrong when sizeof(char_t)>1, and one
test didn't meet the carefully tuned allocation criteria under compact
mode due to the hash table usage and had to be changed a bit.
2018-03-16 21:33:26 -07:00
Arseny Kapoulkine
a55f575a03 tests: Fix OSX test failure
Apparently at some point OSX behavior when reading /dev/tty switched
from "can't open the file" to "the file can be opened and 0 bytes can be
read from it" which generates a wrong error and doesn't exercise the
code path we care about.
2017-12-22 11:30:15 -08:00
Arseny Kapoulkine
7c6d0010b3
Merge pull request #170 from zeux/move
This change implements move ctor and assign support for xml_document.

All node handles remain valid after the move and point to the new document; the only exception is the document node itself (that remains unmoved).

Move is O(document size) in theory because it needs to relocate immediate document children (there is just one in conformant documents) and all memory pages; in practice the memory pages only need the header adjusted, which is ~0.1% of the actual data size.

Move requires no allocations in general, except when using compact mode where some moves need to grow the hash table which can fail (throw).

Fixes #104
2017-11-13 13:24:43 -08:00
Arseny Kapoulkine
58611c8702 tests: Add compact move tests
This helps make sure our error handling logic works and is exercised.
2017-11-13 08:59:16 -08:00
Arseny Kapoulkine
492ebc22bc tests: Fix expansion-to-defined warning
This warning is new as of GCC 7 and highlights undefined behavior in the
preprocessor that ASAN detection was relying on.
2017-11-10 21:35:59 -08:00
Arseny Kapoulkine
0504fa4e90 tests: Add more tests for document move
These tests currently fail for compact mode because of ->reserve()
failing.
2017-10-26 08:36:05 -07:00
Arseny Kapoulkine
b0fc587a7f tests: Add more move tests
We now check that appending a child to a moved document performs no
allocations - this is already the case, but if we neglected to copy the
allocator state this test would fail.
2017-10-20 21:53:42 -07:00
Arseny Kapoulkine
50bc0d5a69 tests: Adjust move coverage tests
Large test wasn't testing shared parent condition properly - add one
more level of hierarchy so that it works as expected.
2017-09-25 22:54:42 -07:00
Arseny Kapoulkine
26ead385a7 tests: Add more move tests
Add a test that checks that static buffer pointer was moved correctly
by checking if offset_debug still works.
2017-09-25 22:52:26 -07:00
Arseny Kapoulkine
402b967fa9 tests: Add more move tests
Make sure we have coverage for empty documents and for large documents
that trigger compact_shared_parent != root for some pages.
2017-09-25 22:47:10 -07:00
Arseny Kapoulkine
faba4786c0 tests: Add more document move tests
Verify that move doesn't allocate and that it preserves structures
required for tree memory management and append_buffer in tact.
2017-09-25 22:38:30 -07:00
Arseny Kapoulkine
6eb7519dba tests: Add basic move tests
These just verify that move ctor/assignment operator work as expected in
simple cases - there are a number of ways in which the internal
structure can be incorrect...
2017-09-25 21:37:56 -07:00