1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 12:25:09 +03:00
Commit Graph

278 Commits

Author SHA1 Message Date
Nick Wellnhofer
e75e878e02 doc: Update and fix documentation 2024-05-20 14:23:39 +02:00
Nick Wellnhofer
ec2f68f164 parser: Report malloc failure in xmlNewInputFromFile 2024-05-14 16:04:56 +02:00
Nick Wellnhofer
4ff2dccf9f SAX2: Warn if URI resolution failed 2024-05-13 12:50:08 +02:00
Nick Wellnhofer
84a71860a8 xmlreader: Fix xmlTextReaderConstEncoding
Regression from commit f1c1f5c6.

Fixes #697.
2024-02-26 15:33:06 +01:00
Nick Wellnhofer
c444c96e20 parser: Report OOM errors even after parser was stopped 2024-02-13 12:23:54 +01:00
Nick Wellnhofer
63986c45b9 parser: Report fatal error if document entity couldn't be loaded
Only lower error level when loading entities.

Fixes #667.
2024-01-22 21:07:41 +01:00
Nick Wellnhofer
12f0bb9478 parser: Synchronize more options 2024-01-05 20:39:40 +01:00
Nick Wellnhofer
3efbe916a1 parser: Mark 'token' member as unused in xmlParserCtxt 2024-01-05 20:39:40 +01:00
Nick Wellnhofer
b82fd81d06 parser: Rework xmlCtxtParseDocument
Make xmlCtxtParseDocument take a parser input which can be popped after
parsing.
2024-01-05 20:39:40 +01:00
Nick Wellnhofer
d0eb5a7e54 parser: Remove xmlErrEncodingInt
Convert the last user to xmlFatalErr.
2024-01-04 15:28:57 +01:00
Nick Wellnhofer
f30b9b2331 fuzz: Add assertion in xmlCopyCharMultibyte
This is an internal function that should never receive out-of-range
codepoints.
2024-01-04 15:28:57 +01:00
Nick Wellnhofer
0821efc8ee encoding: Check whether encoding handlers support input/output
The "HTML" encoding handler doesn't support input which could lead to a
wrong error report.
2024-01-02 19:48:23 +01:00
Nick Wellnhofer
85f99023ae parser: Fix buffer size checks
Don't test size of remaining data. This causes false positives with
memory buffers.

Also impose XML_MAX_HUGE_LENGTH limit when parsing with XML_PARSE_HUGE.
2024-01-02 19:48:23 +01:00
Nick Wellnhofer
16b0dbc1b3 parser: Fix XML_ERR_UNSUPPORTED_ENCODING errors
Commit 45157261 added the check in the wrong place.

Also allow unsupported encoding in xmlNewInputInternal.

Fixes #654.
2024-01-02 14:17:27 +01:00
Nick Wellnhofer
e45a4d7115 io: Always forward IO errors to global handler
The HTTP module raises errors without context. This won't be fixed,
so send them to the global error handler.
2023-12-29 01:22:13 +01:00
Nick Wellnhofer
7e0bbbc143 parser: New input API
Provide a new set of functions to create xmlParserInputs. These can be
used for the document entity or from external entity loaders.

- Don't require xmlParserInputBuffer.
- All functions take a base URI.
- All functions take an encoding as string.
- xmlNewInputURL also takes a public ID.
- xmlNewInputMemory takes a size_t.
- Optimization hints for memory buffers.

Improve documentation.

Only call xmlInitParser before allocating a new parser context.

Call xmlCtxtUseOptions as early as possible.
2023-12-29 01:22:13 +01:00
Nick Wellnhofer
451572615c parser: Downgrade XML_ERR_UNSUPPORTED_ENCODING to warning
If the actual encoding is UTF-8 or ASCII, we don't want to fail.
2023-12-29 01:22:13 +01:00
Nick Wellnhofer
24b7144f2c parser: More refactoring of entity parsing
Remove xmlCreateEntityParserCtxtInternal.

Rework xmlNewEntityInputStream.
2023-12-29 01:22:13 +01:00
Nick Wellnhofer
6a9a88a17f parser: Move progressive flag into input struct 2023-12-29 01:20:08 +01:00
Nick Wellnhofer
d944a41515 parser: Fix in-parameter-entity and in-external-dtd checks
Use in ctxt->input->entity instead of ctxt->inputNr to determine whether
we are inside a parameter entity.

Stop using ctxt->external to check whether we're in an external DTD.
This is signaled by ctxt->inSubset == 2.
2023-12-29 01:19:56 +01:00
Nick Wellnhofer
c1bddd4c26 parser: Mark 'length' member of xmlParserInput as unused 2023-12-25 23:38:40 +01:00
Nick Wellnhofer
955c177f69 parser: Stop using 'directory' struct member
This was only used as a pointless fallback for URI resolution.
2023-12-25 23:38:40 +01:00
Nick Wellnhofer
60841beba6 parser: Make XML_IO_NETWORK_ATTEMPT behave as before
Always reported to generic error, not to parser context for backward
compatibility. Several downstream test suites rely on this behavior.
2023-12-25 23:38:40 +01:00
Nick Wellnhofer
a26934105e io: Move some code from xmlIO.c to parserInternals.c
Move everything related to parser contexts to parserInternals.c.
2023-12-25 23:38:40 +01:00
Nick Wellnhofer
c8f1f4a280 doc: Improve documentation of error handlers 2023-12-21 17:36:17 +01:00
Nick Wellnhofer
130436917c parser: Rename xmlErrParser to xmlCtxtErr 2023-12-21 15:02:24 +01:00
Nick Wellnhofer
8d0aaf4b95 parser: Remove xmlErrEncoding
Use xmlFatalErr or xmlCtxtErrIO.
2023-12-21 15:02:24 +01:00
Nick Wellnhofer
9fbe46ba17 io: Consolidate error messages 2023-12-21 15:02:24 +01:00
Nick Wellnhofer
23345a1cb1 io: Report IO errors through xmlCtxtErrIO
This is also a new public API function to be used in external entity
loaders.
2023-12-21 15:02:24 +01:00
Nick Wellnhofer
7e511f35f1 io: Pass error codes from xmlFileOpenReal to xmlNewInputFromFile
This allows to report the reason why opening a file failed to the parser
context and improve error messages. Now we can also remove the stat call
before opening a file.
2023-12-21 15:02:24 +01:00
Nick Wellnhofer
531d06add6 error: Stop printing some errors by default
Unfortunately, it's long-standing behavior for libxml2 to print all
reported errors to stderr by default. This default behavior is now
partially disabled. If no error handler is set, only parser and
validation errors are passed to a generic error handler or printed to
stderr. Other errors are still available via xmlGetLastError and can be
captured with a structured error handler.
2023-12-21 15:02:24 +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
69d88566b6 malloc-fail: Fix OOM error handling in xmlSwitchInputEncoding
Make sure that in->buffer won't be set to NULL if a memory allocation fails.

Short-lived regression.
2023-12-15 15:03:39 +01:00
Nick Wellnhofer
79a9938d84 parser: Don't grow or shrink pull parser memory buffers
Readd check for memory buffers without a read callback to avoid
XML_MAX_LOOKUP_LIMIT errors if users provide a custom input buffer.
Regressed with commit 834b8123 and later changes.
2023-12-13 19:58:44 +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
bd5ad0308d encoding: Report malloc failures
Introduce new API functions that return a separate error code if a
memory allocation fails.

- xmlOpenCharEncodingHandler
- xmlLookupCharEncodingHandler

Fix a few places where malloc failures weren't reported.
2023-12-11 22:05:47 +01:00
Nick Wellnhofer
43b511fa71 parser: Make CRLF increment line number
Partial revert of cb927e85 fixing CRLFs not incrementing the line
number.

This requires to rework xmlParseQNameHashed. The original implementation
prompted the change to xmlCurrentChar which really shouldn't modify the
'cur' pointer as side effect. But the NEXTL macro relies on this
behavior.

Ultimately, we should reintroduce the change to xmlCurrentChar and fix
the NEXTL macro. This will lead to single CRs incrementing the line
number as well which seems more consistent.

Fixes #628.
2023-11-26 15:18:09 +01:00
Nick Wellnhofer
ff6c318862 include: Remove useless 'const' from function arguments 2023-11-23 15:27:00 +01:00
Nick Wellnhofer
028566745c parser: Remove redundant IS_CHAR check in xmlCurrentChar 2023-10-22 16:32:54 +02:00
Nick Wellnhofer
c082ef4644 parser: Stop switching to ISO-8859-1 on encoding errors
Use U+FFFD Replacement Character if invalid UTF-8 is encountered in
recovery mode.

Also rewrite xmlNextChar and xmlCurrentChar.

Fixes #598.
2023-10-22 16:32:54 +02:00
Nick Wellnhofer
572ecc1719 parser: Fix buffer shrinking when push parsing
Short-lived regression from b76d81da.
2023-10-22 14:01:50 +02:00
Nick Wellnhofer
b76d81dab3 parser: Fix regression when push parsing parameter entities
Short-lived regression from 834b8123.

Also shrink parameter entity buffers when push parsing.
2023-10-06 13:11:19 +02:00
Nick Wellnhofer
eb69c1d39d parser: Fix initialization of namespace data
Move initialization to xmlInitSAXParserCtxt. Also add missing XML_HIDDEN
to xmlParserNsFree.

Fixes #597.
2023-10-02 12:33:29 +02:00
Nick Wellnhofer
e0dd330b8f parser: Use hash tables to avoid quadratic behavior
Use a hash table to lookup namespaces by prefix. The hash table stores
an index into the namespace table. Auxiliary data for namespaces is
stored in a separate array along the main namespace table.

Use a hash table to verify attribute uniqueness. The hash table stores
an index into the attribute table.

Reuse hash value from the dictionary to avoid computing them twice.

See #346.
2023-09-29 12:43:22 +02:00
Nick Wellnhofer
cb927e8519 parser: Don't skip CR in xmlCurrentChar
Skip over carriage returns later in xmlNextChar.
2023-09-29 12:43:08 +02:00
Nick Wellnhofer
b9db3d7d02 parser: Simplify xmlStringCurrentChar
Start to move away from using this function.
2023-09-22 19:01:11 +02:00
Nick Wellnhofer
8c084ebdc7 doc: Make apibuild.py happy 2023-09-21 22:57:33 +02:00
Nick Wellnhofer
9b5cce7a71 include: Remove more unnecessary includes 2023-09-21 01:50:53 +02:00
Nick Wellnhofer
699299cae3 globals: Stop including globals.h 2023-09-20 22:07:40 +02:00
Nick Wellnhofer
11a1839ddd globals: Move remaining globals back to correct header files
This undoes a lot of damage.
2023-09-20 22:06:49 +02:00