1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-12-24 21:33:51 +03:00
Commit Graph

308 Commits

Author SHA1 Message Date
Nick Wellnhofer
dba1ed85a3 ftp: Remove FTP support
Remove the built-in FTP client. If you configure --with-legacy, old
symbols are retained for ABI compatibility.
2024-06-12 18:19:55 +02:00
Nick Wellnhofer
ab5e6debd1 parser: Introduce XML_INPUT_NETWORK input flag
This allows to disable network access when creating parser inputs with
xmlInputCreateUrl.
2024-06-12 16:36:12 +02:00
Nick Wellnhofer
64ad272525 parser: Introduce per-context resource loader 2024-06-12 16:22:52 +02:00
Nick Wellnhofer
b9d2f3c911 parser: Introduce new input API
- xmlInputCreateUrl
- xmlInputCreateMemory
- xmlInputCreateString
- xmlInputCreateFd
- xmlInputCreateIO
- xmlInputSetEncoding

These functions don't take a parser context and work on xmlParserInputs,
replacing functions working on xmlParserInputBuffers.

xmlInputCreateUrl and xmlInputSetEncoding offer fine-grained error
handling.

Several XML_INPUT_* flags offer additional control.
2024-06-12 16:22:52 +02:00
Nick Wellnhofer
ff3b091910 parser: Implement XML_PARSE_NO_UNZIP option 2024-06-12 16:14:15 +02:00
Nick Wellnhofer
1432949d3c io: Pass input flags to xmlParserInputBufferCreateUrl 2024-06-12 16:14:15 +02:00
Nick Wellnhofer
b5890cb425 io: Remove xmlParserInputBufferCreateFilenameSafe 2024-06-12 16:14:15 +02:00
Nick Wellnhofer
1b1e8b3c12 io: Stop invoking generic error handler for IO errors 2024-06-12 16:14:15 +02:00
Nick Wellnhofer
a331526c8e io: Don't report write errors twice 2024-06-12 16:07:20 +02:00
Nick Wellnhofer
717f3a7b21 io: Fix resetting xmlParserInputBufferCreateFilename hook
We don't want to invoke the default function.
2024-06-12 16:04:45 +02:00
Nick Wellnhofer
e75e878e02 doc: Update and fix documentation 2024-05-20 14:23:39 +02:00
Nick Wellnhofer
a4c2b7233f io: Don't set close callback in xmlParserInputBufferCreateFd 2024-05-05 17:27:12 +02:00
Nick Wellnhofer
a279aae30f io: Allocate output buffer with XML_BUFFER_ALLOC_IO
This allows efficient shrinking of memory buffers.

Support IO buffers in xmlBufDetach.
2024-03-18 15:14:43 +01:00
Nick Wellnhofer
c1fe9e72ef io: Report more malloc failures when writing to output buffer 2024-03-15 19:47:08 +01:00
Nick Wellnhofer
67e475b78e http: Improve error message for HTTPS redirects 2024-02-19 11:09:39 +01:00
Nick Wellnhofer
e314109ad1 save: Don't write directly to internal buffer
Make sure that OOM errors are reported.
2024-02-16 16:14:05 +01:00
Nick Wellnhofer
0d170acaba io: Report malloc failure in xmlOutputBufferWrite
Fixes #676.
2024-02-01 11:51:58 +01:00
Nick Wellnhofer
d2b55a7a02 writer: Implement xmlTextWriterClose
This function can be used to make sure that closing the output stream
succeeded.

Fixes #513.
2024-01-05 20:50:00 +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
c2ef78f76e io: Fix close error handling
There's no way to report error codes from closing an output buffer yet.
2023-12-25 23:38:40 +01:00
Nick Wellnhofer
6d27c549e1 io: Fix read/write error handling
Handle short reads/writes from fd. Fix stdio error handling.
2023-12-25 23:38:40 +01:00
Nick Wellnhofer
0bef93bf24 io: More refactoring and unescaping fixes
Merge Windows wrappers into relevant functions.

Remove more unnecessary unescaping.

Merge *OpenW into *Open functions.

Use unbuffered IO for output.
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
8ab1b122c4 Fix filename and URI handling
Many strings are passed to the library that could be either URIs or
filesystem paths. We now assume that strings are a URI if they contain
the substring "://". This means that they have a scheme and an
authority. Otherwise, URI resolution wouldn't make much sense.

Fix xmlBuildURI to work with filesystem paths. If the base URI doesn't
contain "://" it is treated as filename. The resolved URI is unescaped,
appended and the result is normalized. Rewrite xmlNormalizePath to
handle Windows quirks.

All special handling for Windows paths is removed in xmlCanonicPath.
If the path looks like an URI, only escape characters allowed in Legacy
Extended IRIs.

Make xmlPathToURI only call xmlCanonicPath. Theh additional round-trip
through URI parser and serializer seems useless.

Add a helper function xmlConvertUriToPath in xmlIO.c which checks for
file URIs and unescapes them.

Always process strings with xmlCanonicPath in xmlLoadExternalEntity.
This should be harmless now.

Should help with #334, #387, #611.
2023-12-25 23:38:40 +01:00
Nick Wellnhofer
229e5ff7f9 io: Remove support for HTTP POST
This feature is unlikely to be used these days.
2023-12-24 22:11:49 +01:00
Nick Wellnhofer
0a658c0f0a io: Don't use "-" to read from stdin
To implement this feature on such a low level is a disaster waiting to
happen. Remove these checks from the IO code and move them to xmllint.

Note that the serialization API will still treat "-" as stdout.
2023-12-21 15:02:24 +01:00
Nick Wellnhofer
c9a46a91fe io: Rework initialization 2023-12-21 15:02:24 +01:00
Nick Wellnhofer
b75fc1ab33 io: Rearrange code 2023-12-21 15:02:24 +01:00
Nick Wellnhofer
130436917c parser: Rename xmlErrParser to xmlCtxtErr 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
1ef3566362 io: Always use unbuffered input
Before, we often used unbuffered input via the lzma or gzip handlers,
more or less inadvertently.

Change the default file handlers from buffered (stdc FILE) to unbuffered
(POSIX fds).
2023-12-21 15:02:24 +01:00
Nick Wellnhofer
7e14c05df2 io: Fix detection of compressed streams
Make sure that we don't try to open uncompressed streams with a
compression handler in copying mode.
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
b2dbcc432b io: Rework default callbacks
Register a dummy callback struct for default callbacks. Handle them in a
separate function which will later allow to return meaningful error
codes.
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
c5a8aef2f6 error: Refactor error reporting
Introduce xmlStrVASPrintf, trying to handle buggy snprintf
implementations.

Introduce xmlSetError to set errors atomically.

Introduce xmlUpdateError to set an error, fixing up node, file and line.

Introduce helper function xmlRaiseMemoryError.

Make legacy error handlers call xmlReportError, avoiding checks in
xmlVRaiseError.

Remove fragile support for getting file and line info from XInclude
nodes.
2023-12-21 02:46:27 +01:00
Nick Wellnhofer
c2bbeed1fd io: Fix memory lifetime issue with input buffers
xmlParserInputBufferCreateMem must make a copy of the buffer.

This fixes a regression from 2.11 which could cause reads from freed
memory depending on the use case.

Undeprecate xmlParserInputBufferCreateStatic which can avoid copying
the whole buffer.
2023-12-12 23:51:32 +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
455c61d635 Remove VMS support
This was last updated 10 years ago and is most likely broken.
2023-11-23 15:59:41 +01: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
Nick Wellnhofer
4e1c13ebfd debug: Remove debugging code
This is barely useful these days and only clutters the code base.
2023-09-19 17:35:09 +02:00
Nick Wellnhofer
95e81a360c parser: Decode all data in xmlCharEncInput
Even with flush set to true, xmlCharEncInput didn't guarantee to decode
all data. This complicated the push parser.

Remove the flush flag and always decode all available data.

Also fix ICU code where the flush flag has a different meaning. Always
set flush to false and retry even with empty input buffers.
2023-08-08 15:21:31 +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
4ee0815514 encoding: Move rawconsumed accounting to xmlCharEncInput 2023-08-08 15:19:51 +02:00
Nick Wellnhofer
ec7be50662 parser: Rework encoding detection
Introduce XML_INPUT_HAS_ENCODING flag for xmlParserInput which is set
when xmlSwitchEncoding is called. The parser can use the flag to
reliably detect whether an encoding was already set via user override,
BOM or other auto-detection. In this case, the encoding declaration
won't be used to switch the encoding.

Before, an inscrutable mix of ctxt->charset, ctxt->input->encoding
and ctxt->input->buf->encoder was used.

Introduce private helper functions to switch encodings used by both the
XML and HTML parser:

- xmlDetectEncoding which skips over the BOM, allowing to remove the
  BOM checks from other encoding functions.
- xmlSetDeclaredEncoding, replacing htmlCheckEncodingDirect, which warns
  about encoding mismatches.

If users override the encoding, store the declared instead of the actual
encoding in xmlDoc. In this case, the actual encoding is known and the
raw value from the doc is more useful.

Also use the input flags to store the ISO-8859-1 fallback state.
Restrict the fallback to cases where no encoding was specified. (The
fallback is only useful in recovery mode and these days broken UTF-8 is
probably more likely than ISO-8859-1, so it might eventually be removed
completely.)

The 'charset' member of xmlParserCtxt is now unused. The 'encoding'
member of xmlParserInput is now unused.

The 'standalone' member of xmlParserInput is renamed to 'flags'.

A new parser state XML_PARSER_XML_DECL is added for the push parser.
2023-08-08 15:19:46 +02:00
Nick Wellnhofer
b230861dbd xmlIO: Remove some calls to xmlIOErr
The xmlIOErr functions use the global error handler and should be
avoided if possible.
2023-04-30 21:45:39 +02:00
Nick Wellnhofer
320f5084cd parser: Improve handling of encoding and IO errors
Make sure that xmlCharEncInput, xmlParserInputBufferPush and
xmlParserInputBufferGrow set the correct error code in the
xmlParserInputBuffer. Handle errors when calling these functions.
2023-04-30 21:31:54 +02:00
Nick Wellnhofer
97086fd76b malloc-fail: Fix memory leak in xmlParserInputBufferCreateMem
Found with libFuzzer, see #344.
2023-02-17 17:16:50 +01:00