HTMLparser.c


Log

Author Commit Date CI Message
Nick Wellnhofer 0447275e 2024-12-15T21:17:07 html: Check reallocations for overflow
Nick Wellnhofer 6548ba11 2024-12-13T16:37:40 parser: Fix argument checks in xmlCtxtParse* - Raise invalid argument error. - Free input stream if ctxt is NULL.
Nick Wellnhofer 497081ba 2024-11-17T20:25:07 parser: Remove remaining calls to xml{Push|Pop}Input
Nick Wellnhofer 0f4f8900 2024-11-17T20:13:14 parser: Rename inputPush to xmlCtxtPushInput
Nick Wellnhofer 225ed707 2024-09-26T22:38:24 html: Accelerate htmlParseCharData
Nick Wellnhofer 20799979 2024-09-26T17:09:40 html: Handle numeric character references directly
Nick Wellnhofer 0bc4608c 2024-09-15T20:28:49 html: Use hash table to check for duplicate attributes
Nick Wellnhofer 24a6149f 2024-09-15T19:18:40 html: Make sure that character data mode is reset
Nick Wellnhofer c32397d5 2024-09-12T22:39:05 html: Improve character class macros
Nick Wellnhofer e8406554 2024-09-12T15:21:03 html: Rewrite parsing of most data
Nick Wellnhofer f77ec16d 2024-09-12T01:45:34 html: Optimize htmlParseCharData
Nick Wellnhofer 440bd64c 2024-09-12T04:01:38 html: Optimize htmlParseHTMLName
Nick Wellnhofer 6040785a 2024-09-12T23:12:01 html: Deprecate AutoClose API
Nick Wellnhofer 188cad68 2024-09-12T02:51:20 html: Remove obsolete content model
Nick Wellnhofer 0144f662 2024-09-12T02:30:10 html: Remove obsolete code
Nick Wellnhofer 575be6c1 2024-09-12T01:40:07 html: Fix line numbers with CRs
Nick Wellnhofer be874d78 2024-09-11T19:47:07 html: Ignore unexpected DOCTYPE declarations
Nick Wellnhofer 462bf0b7 2024-09-11T19:06:06 html: Rework options Introduce htmlCtxtSetOptions, see similar changes made to XML parser. Add HTML_PARSE_HUGE alias. Support HTML_PARSE_BIG_LINES.
Nick Wellnhofer 42c3823d 2024-09-11T19:05:09 html: Update comment
Nick Wellnhofer 9f04cce6 2024-09-11T17:43:07 html: Remove unused or useless return codes htmlParseStartTag should always succeed (except for malloc failures).
Nick Wellnhofer e179f3ec 2024-09-11T17:29:59 html: Stop reporting syntax errors It doesn't make much sense to keep the old syntax error handling which doesn't conform to HTML5. Handling HTML5 parser errors is rather involved and not essential for parsers.
Nick Wellnhofer 27752f75 2024-09-11T15:06:55 html: Fix EOF handling in start tags
Nick Wellnhofer b19d3539 2024-09-11T15:03:49 html: Fix EOF handling in comments
Nick Wellnhofer 17e56ac5 2024-09-11T14:24:58 html: Fix parsing of end tags
Nick Wellnhofer 24a09033 2024-09-09T02:53:14 html: Fix bogus end tags
Nick Wellnhofer bca64854 2024-09-09T02:30:18 html: Allow U+000C FORM FEED as whitespace
Nick Wellnhofer 6edf1a64 2024-09-09T02:09:20 html: Fix DOCTYPE parsing
Nick Wellnhofer 9678163f 2024-09-09T02:01:19 html: Don't check for valid XML characters
Nick Wellnhofer a6955c13 2024-09-08T23:19:49 html: Parse numeric character references according to HTML5
Nick Wellnhofer 4eeac309 2024-09-08T22:20:20 html: Start to fix EOF and U+0000 handling
Nick Wellnhofer e062a4a9 2024-09-08T20:40:36 html: Add HTML5 parser option This option passes tokenizer output directly to the SAX callbacks, making it possible to test the tokenizer against the html5lib test suite. This will produce unbalanced calls to the startElement and endElement callbacks, but it's the only way to support a SAX like interface for HTML5. It can be used for filtering or rewriting HTML5, for example. A HTML5 tree builder could then be implemented on top of the SAX callbacks.
Nick Wellnhofer 17da54c5 2024-09-08T19:16:12 html: Normalize newlines
Nick Wellnhofer 341dc78f 2024-09-08T19:11:14 html: Deduplicate code in htmlCurrentChar
Nick Wellnhofer 3adb396d 2024-09-07T15:18:13 html: Parse bogus comments instead of ignoring them Also treat XML processing instructions as bogus comments.
Nick Wellnhofer 84440175 2024-09-07T14:21:12 html: Add missing calls to htmlCheckParagraph()
Nick Wellnhofer 86d6b9b0 2024-09-07T04:18:06 html: Deduplicate some code
Nick Wellnhofer 0d324bde 2024-09-07T03:45:09 html: Simplify node info accounting
Nick Wellnhofer ccb61f59 2024-09-07T03:15:50 html: Remove duplicate calls to htmlAutoClose
Nick Wellnhofer f9ed30e9 2024-09-06T17:49:04 html: HTML5 character data states
Nick Wellnhofer 59511792 2024-09-03T15:52:44 html: Parse named character references according to HTML5
Nick Wellnhofer d5cd0f07 2022-07-15T17:00:36 html: Prefer SKIP(1) over NEXT in HTML parser Use SKIP(1) where it's safe to avoid a function call.
Nick Wellnhofer dc2d4983 2023-05-04T17:47:38 html: Rework htmlLookupSequence Rename to htmlLookupString and use strstr for increased performance.
Nick Wellnhofer 637215a4 2023-05-04T17:16:51 html: Always terminate doctype declarations on '>' Align with HTML5 spec. This allows to remove the old quote handling in htmlLookupSequence.
Nick Wellnhofer 72e29f9a 2023-05-04T17:03:22 html: Fix quadratic behavior in push parser Fix quadratic behavior related to unquoted attribute values. We really have to replicate parts of the HTML5 state machine to find the end of tags relibably. Fixes #533.
Nick Wellnhofer a80f8b64 2023-05-04T15:59:31 html: Allow attributes in end tags Attribute are syntactically allowed in HTML5 end tags but otherwise ignored.
Nick Wellnhofer f2272c23 2023-05-04T15:33:27 html: Handle unexpected-solidus-in-tag according to HTML5
Nick Wellnhofer 939b53ee 2023-05-04T15:25:24 html: Stop skipping tag content Tag and attributes names should always be parsed succesfully now.
Nick Wellnhofer dcb2abb2 2023-05-04T15:16:29 html: Parse tag and attribute names according to HTML5 HTML5 allows bascially all characters in tag and attribute names.
Nick Wellnhofer 5d36664f 2024-07-16T00:35:53 memory: Deprecate xmlGcMemSetup
Nick Wellnhofer 8af55c8d 2024-07-06T22:14:21 parser: Rename new input API functions These weren't made public yet.
Nick Wellnhofer d74ca594 2024-07-06T22:04:06 parser: Rename internal xmlNewInput functions
Nick Wellnhofer 4f329dc5 2024-07-10T03:27:47 parser: Implement xmlCtxtParseContent This implements xmlCtxtParseContent, a better alternative to xmlParseInNodeContext or xmlParseBalancedChunkMemory. It accepts a parser context and a parser input, making it a lot more versatile. xmlParseInNodeContext is now implemented in terms of xmlCtxtParseContent. This makes sure that xmlParseInNodeContext never modifies the target document, improving thread safety. xmlParseInNodeContext is also more lenient now with regard to undeclared entities. Fixes #727.
Nick Wellnhofer 2e63656e 2024-07-07T19:21:46 parser: Check return value of inputPush inputPush typically doesn't fail because we pre-allocate the input table. The return value should be checked nevertheless.
Nick Wellnhofer fdfeecfe 2024-07-02T21:54:26 parser: Reenable ctxt->directory Unused internally, but used in downstream code. Should fix #753.
Nick Wellnhofer 30ef7755 2024-07-02T04:02:16 parser: Don't use deprecated xmlCopyChar
Nick Wellnhofer dd8e3785 2024-06-28T21:15:27 HTML: Rework UTF8ToHtml Optimize code. Check for XML_ENC_ERR_SPACE. Use error macros.
Nick Wellnhofer f505dcae 2024-06-26T14:11:34 tree: Remove underscores from xmlRegisterCallbacks
Nick Wellnhofer 1112699c 2024-06-17T02:42:18 legacy: Remove most legacy functions from public headers Also remove warning messages.
Nick Wellnhofer 039ce1e8 2024-06-14T16:41:43 parser: Pass global object to sax->setDocumentLocator Revert part of commit c011e760. Fixes #732.
Nick Wellnhofer 89fcae4d 2024-06-11T16:19:58 parser: Don't report malloc failures when creating context We don't want messages to stderr before an error handler could be set on a parser context.
Nick Wellnhofer e75e878e 2024-05-20T13:58:22 doc: Update and fix documentation
Nick Wellnhofer a4c2b723 2024-05-05T17:26:31 io: Don't set close callback in xmlParserInputBufferCreateFd
Nick Wellnhofer 05654cfe 2024-04-28T17:54:20 html: Deprecate htmlHandleOmittedElem
Nick Wellnhofer aa04838e 2024-03-26T14:10:58 html: Use binary search in htmlEntityValueLookup
Nick Wellnhofer 3efbe916 2024-01-05T00:11:29 parser: Mark 'token' member as unused in xmlParserCtxt
Nick Wellnhofer b82fd81d 2024-01-04T23:25:06 parser: Rework xmlCtxtParseDocument Make xmlCtxtParseDocument take a parser input which can be popped after parsing.
Nick Wellnhofer 7e0bbbc1 2023-12-27T18:33:30 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.
Nick Wellnhofer 6a9a88a1 2023-12-26T03:13:05 parser: Move progressive flag into input struct
Nick Wellnhofer d944a415 2023-12-26T02:10:35 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.
Nick Wellnhofer 477a7ed8 2023-12-28T19:06:32 html: Abort earlier on fatal errors
Nick Wellnhofer c1bddd4c 2023-12-23T01:09:17 parser: Mark 'length' member of xmlParserInput as unused
Nick Wellnhofer 955c177f 2023-12-23T00:58:36 parser: Stop using 'directory' struct member This was only used as a pointless fallback for URI resolution.
Nick Wellnhofer 8cd56317 2023-12-21T02:32:01 html: Don't close fd in htmlCtxtReadFd Long-standing bug. The XML fix from 2003 was never ported to the HTML parser. htmlReadFd was fixed with fe6890e2.
Nick Wellnhofer 13043691 2023-12-20T00:33:34 parser: Rename xmlErrParser to xmlCtxtErr
Nick Wellnhofer 8d0aaf4b 2023-12-19T20:47:36 parser: Remove xmlErrEncoding Use xmlFatalErr or xmlCtxtErrIO.
Nick Wellnhofer 54c70ed5 2023-12-18T19:31:29 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.
Nick Wellnhofer c2bbeed1 2023-12-12T23:51:32 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.
Nick Wellnhofer abd74186 2023-12-10T19:07:32 html: Report malloc failures Fix many places where malloc failures aren't reported. Stop checking for ctxt->instate.
Nick Wellnhofer c011e760 2023-12-06T01:09:31 globals: Remove unused globals from thread storage Setting these deprecated globals hasn't had an effect for a long time. Make them constants. This reduces the size of per-thread storage from ~700 to ~250 bytes.
Nick Wellnhofer c7629c9e 2023-11-30T16:52:34 parser: Clarify documentation regarding xmlReadMemory buffer size Fixes #638.
Nick Wellnhofer e3959461 2023-11-30T16:15:46 html: Reenable buggy detection of XML declarations Switch to UTF-8 if a document starts with '<?xm' to match old behavior. Also enable this check in the push parser. Fixes #637.
Nick Wellnhofer ff6c3188 2023-11-23T15:22:59 include: Remove useless 'const' from function arguments
Nick Wellnhofer b9db3d7d 2023-09-22T15:45:20 parser: Simplify xmlStringCurrentChar Start to move away from using this function.
Nick Wellnhofer 8c084ebd 2023-09-21T22:57:33 doc: Make apibuild.py happy
Nick Wellnhofer c5890716 2023-09-21T17:01:35 html: Fix logic in htmlAutoClose Note that the function is never called with a NULL newtag. Fixes #591.
Nick Wellnhofer 9b5cce7a 2023-09-21T00:44:50 include: Remove more unnecessary includes
Nick Wellnhofer 11a1839d 2023-09-20T17:54:48 globals: Move remaining globals back to correct header files This undoes a lot of damage.
Nick Wellnhofer 4e1c13eb 2023-09-18T14:45:10 debug: Remove debugging code This is barely useful these days and only clutters the code base.
Nick Wellnhofer e48f2695 2023-08-29T17:41:18 parser: Remove push parser debugging code
Nick Wellnhofer 0d24fc0a 2023-08-14T12:53:49 html: Remove encoding hack in htmlCreateFileParserCtxt Switch encoding directly instead of calling htmlCheckEncoding with faked content.
Nick Wellnhofer 5db5a704 2023-08-09T18:39:14 html: Fix UAF in htmlCurrentChar Short-lived regression found by OSS-Fuzz.
Nick Wellnhofer 95e81a36 2023-08-08T15:21:31 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.
Nick Wellnhofer 834b8123 2023-08-08T15:21:28 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.
Nick Wellnhofer facc2a06 2023-08-08T15:21:21 parser: Don't overwrite EOF parser state
Nick Wellnhofer 59fa0bb3 2023-08-08T15:21:14 parser: Simplify input pointer updates The base member always points to the beginning of the buffer.
Nick Wellnhofer ec7be506 2023-08-08T15:19:46 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.
Nick Wellnhofer 3a64f394 2023-08-08T15:19:25 html: Remove some debugging code in htmlParseTryOrFinish
Nick Wellnhofer 20f5c734 2023-06-07T14:05:34 parser: Recover more input from encoding errors Don't halt the parser in xmlParserGrow to allow more input to be recovered in case of encoding errors. Fixes #543.
Nick Wellnhofer 320f5084 2023-04-30T18:25:09 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.
Nick Wellnhofer 1061537e 2023-03-26T22:40:54 malloc-fail: Fix buffer overread with HTML doctype declarations Found by OSS-Fuzz, see #344.