1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-31 21:50:33 +03:00
Commit Graph

98 Commits

Author SHA1 Message Date
Nick Wellnhofer
b62ccf7f10 fuzz: Add fuzzer for XML reader API 2024-04-22 12:44:12 +02:00
Nick Wellnhofer
971ce40409 fuzz: Also set fuzzAllocFailed if a real allocation fails
Avoid false positives in real OOM situations.
2024-04-14 19:40:22 +02:00
Nick Wellnhofer
1f18d37798 fuzz: Add a few more comments 2024-04-09 13:04:50 +02:00
Nick Wellnhofer
fe3cbf897e fuzz: Check node type before xmlDocSetRootElement 2024-03-29 15:29:53 +01:00
Nick Wellnhofer
ea0ee36546 tree: Align xmlAddChild with other node insertion functions
Make xmlAddChild unlink the child before insertion. Originally, linked
children would most likely cause tree corruption. The first fix
disallowed linked nodes, but there are cases where insertion of such
nodes could succeed.

Don't abort if the node is already a child of parent. In this case,
the node will be moved to the end of the child list.
2024-03-29 12:57:20 +01:00
Nick Wellnhofer
bfb02fbca9 fuzz: Fix xmlSetProp in API fuzzer
Finding the old attribute node is a bit more involved.
2024-03-28 11:30:05 +01:00
Nick Wellnhofer
887ad90a1a fuzz: Restrict input size of API fuzzer 2024-03-26 14:23:51 +01:00
Nick Wellnhofer
6c5248e2a9 fuzz: Restrict number of copies in API fuzzer
Avoid timeouts with large inputs.
2024-03-26 14:21:47 +01:00
Nick Wellnhofer
52efb20a18 fuzz: Enable float-divide-by-zero on OSS-Fuzz
This was recently disabled globally:

    https://github.com/google/oss-fuzz/pull/11567
2024-03-24 13:43:25 +01:00
Nick Wellnhofer
d8741b8196 fuzz: Fix namespaces after xmlDOMWrapRemoveNode 2024-03-22 14:55:22 +01:00
Nick Wellnhofer
d4d1f3f33d fuzz: Enable API fuzzer on OSS-Fuzz 2024-03-20 18:45:10 +01:00
Nick Wellnhofer
5ea2970357 fuzz: Reorder API fuzzer ops 2024-03-20 18:41:26 +01:00
Nick Wellnhofer
da32c852a4 fuzz: Check text nodes after merging
Avoid exponential growth of text.
2024-03-20 18:33:40 +01:00
Nick Wellnhofer
3f05508a53 tree: Report malloc failures in attribute setters 2024-03-18 15:14:43 +01:00
Nick Wellnhofer
6a49bb777c tree: Introduce xmlSearchNsSafe
After the failed experiment with a static XML namespace, introduce
versions of xmlSearchNs that report malloc failures.

Optimize the no-document case by only adding the XML namespace
declaration if it wasn't found in an ancestor.
2024-03-17 21:07:46 +01:00
Nick Wellnhofer
c0edd792ba fuzz: Move fuzzer options to environment variable 2024-03-16 15:20:08 +01:00
Nick Wellnhofer
55175f7537 fuzz: Add OSS-Fuzz build.sh
Move build.sh to our repo to facilitate changes.
2024-03-15 22:07:23 +01:00
Nick Wellnhofer
f14f089fe3 fuzz: Add some comments in api.c 2024-03-15 22:07:23 +01:00
Nick Wellnhofer
ee0c1f87c0 fuzz: New tree API fuzzer 2024-03-15 19:54:27 +01:00
Nick Wellnhofer
ce8f3d2c1d fuzz: Improve README 2024-03-10 15:04:00 +01:00
Nick Wellnhofer
d463733fce fuzz: Reenable malloc failure check when serializing 2024-02-04 14:33:19 +01:00
Nick Wellnhofer
84e50a0c48 fuzz: Don't check for malloc failures when serializing
DTD serialization doesn't report malloc failures yet.
2024-02-01 17:02:24 +01:00
Nick Wellnhofer
fd801845c8 fuzz: Cap URL size
Cap URL size to avoid quadratic behavior when generating error messages.
2024-01-07 16:33:30 +01:00
Nick Wellnhofer
83c1ae13d8 fuzz: Add missing include
Fix build failure.
2024-01-07 15:42:46 +01:00
Nick Wellnhofer
30d839776a fuzz: Disable catalogs
The catalogs API doesn't report OOM errors. It's basically impossible
to use it safely in its current form.
2024-01-04 15:18:14 +01:00
Nick Wellnhofer
54c70ed57f parser: Improve error handling
Introduce xmlCtxtSetErrorHandler allowing to set a structured error for
a parser context. There already was the "serror" SAX handler but this
always receives the parser context as argument.

Start to use xmlRaiseMemoryError.

Remove useless arguments from memory error functions. Rename
xmlErrMemory to xmlCtxtErrMemory.

Remove a few calls to xmlGenericError.

Remove support for runtime entity debugging.
2023-12-21 02:46:27 +01:00
Nick Wellnhofer
4e23892cf0 fuzz: Enable value profile 2023-12-11 22:13:06 +01:00
Nick Wellnhofer
abd74186f9 html: Report malloc failures
Fix many places where malloc failures aren't reported.

Stop checking for ctxt->instate.
2023-12-11 22:13:06 +01:00
Nick Wellnhofer
e115194e6f fuzz: Check malloc failure reports in XML fuzzers 2023-12-11 22:13:06 +01:00
Nick Wellnhofer
f19a95108a parser: Report malloc failures
Fix many places where malloc failures aren't reported.

Make xmlErrMemory public. This is useful for custom external entity
loaders.

Introduce new API function xmlSwitchEncodingName.

Change the way how we store whether the the parser is stopped. This used
to be signaled by setting ctxt->instate to XML_PARSER_EOF which was
misdesigned and error-prone. Set ctxt->disableSAX to 2 instead and
introduce a macro PARSER_STOPPED. Also stop to remove parser inputs in
xmlHaltParser. This allows to remove many checks of ctxt->instate.

Introduce xmlErrParser to handle errors if a parser context is
available.
2023-12-11 22:13:05 +01:00
Nick Wellnhofer
1a354d5b30 regexp: Report malloc failures
Fix places where malloc failures aren't reported.
2023-12-11 22:13:05 +01:00
Nick Wellnhofer
e632d9f02e xpath: Report malloc failures
Fix many places where malloc failures aren't reported.

Rework XPath object cache to store free objects in a linked list to
avoid allocating an additional array. Remove some unneeded object pools.
2023-12-11 22:13:05 +01:00
Nick Wellnhofer
da996c8d0f uri: Report malloc failures
Fix many places where malloc failures weren't reported, for example
after calling xmlStrdup.

Introduce new public API functions that return a separate error code if
a memory allocation fails:

- xmlParseURISafe
- xmlBuildURISafe
- xmlBuildRelativeURISafe

Update the fuzzer to check whether malloc failures are reported.
2023-12-11 22:05:47 +01:00
Nick Wellnhofer
ec7f65069a tests: Fix tests --with-valid --without-xinclude
Fix a copy/paste error from commit 4eba9f9c.

Fixes #632.
2023-11-27 18:03:01 +01:00
Nick Wellnhofer
4f132bcdb3 fuzz: Raise rss_limit_mb 2023-10-15 13:04:54 +02:00
Nick Wellnhofer
c13a019134 fuzz: Test xmlTextReaderRead after EOF or failure 2023-10-15 13:04:54 +02:00
Nick Wellnhofer
e019d97fd0 fuzz: Test XML_PARSE_XINCLUDE | XML_PARSE_VALID 2023-10-15 13:04:54 +02:00
Nick Wellnhofer
fa48187304 fuzz: Disable XML_PARSE_SAX1 option in xml fuzzer
There a no plans to fix quadratic behavior in the legacy SAX1 interface.
2023-09-30 14:45:53 +02:00
Nick Wellnhofer
b7d56ef7f1 malloc-fail: Report malloc failure in xmlRegEpxFromParse
Also check whether malloc failures are reported when fuzzing.
2023-09-22 19:53:11 +02:00
Nick Wellnhofer
f98fa86318 regexp: Fix status codes and handle invalid UTF-8
Fixes #561.
2023-09-22 19:01:11 +02:00
Nick Wellnhofer
f9d717af97 fuzz: Allow to fuzz without push, reader or output modules 2023-09-21 13:05:49 +02:00
Nick Wellnhofer
da274bfa55 build: Fix build when certain modules are disabled 2023-09-21 02:26:43 +02:00
Nick Wellnhofer
834b8123ef parser: Stream data when reading from memory
Don't create a copy of the whole input buffer. Read the data chunk by
chunk to save memory.

Historically, it was probably envisioned to read data from memory
without additional copying. This doesn't work reliably with the current
design of the XML parser which requires a terminating null byte at the
end of input buffers. This lead to xmlReadMemory interfaces, which
expect pointer and size arguments, being changed to make a
zero-terminated copy of the input buffer. Interfaces based on
xmlReadDoc, which actually expect a zero-terminated string and
would make zero-copy operation work, were then simplified to rely on
xmlReadMemoryi, resulting in an unnecessary copy.

To avoid copying (possibly gigabytes) of memory temporarily, we now
stream in-memory input just like content read from files in a
chunk-by-chunk fashion (using a somewhat outdated INPUT_CHUNK size of
250 bytes). As a side effect, we also avoid another copy of the whole
input when handling non-UTF-8 data which was made possible by some
earlier commits.

Interfaces expecting zero-terminated strings now make use of strnlen
which unfortunately isn't part of the standard C library and only
mandated since POSIX 2008.
2023-08-08 15:21:28 +02:00
Nick Wellnhofer
5f4ec41bae fuzz: Add valid.options 2023-03-12 19:47:07 +01:00
Nick Wellnhofer
f6fddb78a5 fuzz: Also test init function of URI fuzzer 2023-03-12 16:20:31 +01:00
Nick Wellnhofer
4eba9f9cfc fuzz: Separate fuzzer for DTD validation 2023-03-12 16:19:33 +01:00
Nick Wellnhofer
42322eba82 fuzz: Inject random malloc failures
Fixes #344.
2023-03-08 14:14:22 +01:00
Nick Wellnhofer
7cd2676277 fuzz: Add maxAlloc item to static seed corpus 2023-03-08 14:07:15 +01:00
Nick Wellnhofer
541b1e2850 fuzz: Support variable integer sizes in fuzz data
Also switch to big-endian.
2023-03-08 13:59:00 +01:00
Nick Wellnhofer
f560065f4d fuzz: Fix duplicate detection in fuzzEntityRecorder
Store a non-NULL value in the hash.
2023-02-28 21:23:11 +01:00