From 8064c23f1f3486e4c929057969fcd7b63b82322d Mon Sep 17 00:00:00 2001 From: 4ngv4eek4k1hpa <4ngv4eek4k1hpa@users.noreply.github.com> Date: Fri, 7 Aug 2026 03:51:45 +0200 Subject: [PATCH 1/3] fix: RSS channel metadata leakage / crash, and ZIP option forwarding Signed-off-by: 4ngv4eek4k1hpa <4ngv4eek4k1hpa@users.noreply.github.com> --- .../markitdown/converters/_rss_converter.py | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/markitdown/src/markitdown/converters/_rss_converter.py b/packages/markitdown/src/markitdown/converters/_rss_converter.py index bec42484fb..a407c9a76b 100644 --- a/packages/markitdown/src/markitdown/converters/_rss_converter.py +++ b/packages/markitdown/src/markitdown/converters/_rss_converter.py @@ -107,7 +107,9 @@ def _parse_atom_type(self, doc: Document) -> DocumentConverterResult: title = self._get_data_by_tag_name(root, "title") subtitle = self._get_data_by_tag_name(root, "subtitle") entries = root.getElementsByTagName("entry") - md_text = f"# {title}\n" + md_text = "" + if title: + md_text += f"# {title}\n" if subtitle: md_text += f"{subtitle}\n" for entry in entries: @@ -143,8 +145,11 @@ def _parse_rss_type(self, doc: Document) -> DocumentConverterResult: channel_title = self._get_data_by_tag_name(channel, "title") channel_description = self._get_data_by_tag_name(channel, "description") items = channel.getElementsByTagName("item") + # Initialize before conditionals: feeds may omit entirely + # (would otherwise raise UnboundLocalError on the first +=). + md_text = "" if channel_title: - md_text = f"# {channel_title}\n" + md_text += f"# {channel_title}\n" if channel_description: md_text += f"{channel_description}\n" for item in items: @@ -179,14 +184,18 @@ def _parse_content(self, content: str) -> str: def _get_data_by_tag_name( self, element: Element, tag_name: str ) -> Union[str, None]: - """Get data from first child element with the given tag name. - Returns None when no such element is found. + """Get data from the first *direct* child element with the given tag name. + + ``Element.getElementsByTagName`` is recursive, so using it for channel + or feed metadata would incorrectly pick up nested ``<item>`` / + ``<entry>`` titles when the parent omits its own ``<title>``. + Returns None when no such direct child is found. """ - nodes = element.getElementsByTagName(tag_name) - if not nodes: - return None - fc = nodes[0].firstChild - if fc: - if hasattr(fc, "data"): + for node in element.childNodes: + if getattr(node, "tagName", None) != tag_name: + continue + fc = node.firstChild + if fc and hasattr(fc, "data"): return fc.data + return None return None From 992d6f2f21929036cbfff3ce1e80cb9fdb9fc902 Mon Sep 17 00:00:00 2001 From: 4ngv4eek4k1hpa <4ngv4eek4k1hpa@users.noreply.github.com> Date: Fri, 7 Aug 2026 03:51:47 +0200 Subject: [PATCH 2/3] fix: RSS channel metadata leakage / crash, and ZIP option forwarding Signed-off-by: 4ngv4eek4k1hpa <4ngv4eek4k1hpa@users.noreply.github.com> --- .../markitdown/src/markitdown/converters/_zip_converter.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/markitdown/src/markitdown/converters/_zip_converter.py b/packages/markitdown/src/markitdown/converters/_zip_converter.py index f87e6c890f..8091fdead7 100644 --- a/packages/markitdown/src/markitdown/converters/_zip_converter.py +++ b/packages/markitdown/src/markitdown/converters/_zip_converter.py @@ -95,15 +95,21 @@ def convert( with zipfile.ZipFile(file_stream, "r") as zipObj: for name in zipObj.namelist(): + # Directory entries end with "/" and have no file payload. + if name.endswith("/"): + continue try: z_file_stream = io.BytesIO(zipObj.read(name)) z_file_stream_info = StreamInfo( extension=os.path.splitext(name)[1], filename=os.path.basename(name), ) + # Forward caller options (e.g. keep_data_uris) into nested + # conversions so ZIP members behave like standalone files. result = self._markitdown.convert_stream( stream=z_file_stream, stream_info=z_file_stream_info, + **kwargs, ) if result is not None: md_content += f"## File: {name}\n\n" From 813d1ac7805b19e576e3d27d5e0d6c5fc09d020d Mon Sep 17 00:00:00 2001 From: 4ngv4eek4k1hpa <4ngv4eek4k1hpa@users.noreply.github.com> Date: Fri, 7 Aug 2026 03:51:49 +0200 Subject: [PATCH 3/3] fix: RSS channel metadata leakage / crash, and ZIP option forwarding Signed-off-by: 4ngv4eek4k1hpa <4ngv4eek4k1hpa@users.noreply.github.com> --- .../markitdown/tests/test_rss_zip_fixes.py | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 packages/markitdown/tests/test_rss_zip_fixes.py diff --git a/packages/markitdown/tests/test_rss_zip_fixes.py b/packages/markitdown/tests/test_rss_zip_fixes.py new file mode 100644 index 0000000000..ff242ef1f7 --- /dev/null +++ b/packages/markitdown/tests/test_rss_zip_fixes.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +"""Regression tests for RSS metadata / crash fixes and ZIP option forwarding.""" + +import io +import zipfile + +from markitdown import MarkItDown, StreamInfo +from markitdown.converters._rss_converter import RssConverter + + +def test_rss_no_channel_title_does_not_crash_or_leak_item_title(): + """Feeds without a channel <title> must not crash or steal an item title.""" + xml = ( + b'<?xml version="1.0"?><rss version="2.0"><channel>' + b"<description>Only desc</description>" + b"<item><title>Item Onebody" + b"" + ) + result = RssConverter().convert(io.BytesIO(xml), StreamInfo(extension=".rss")) + assert result.title is None + # Channel heading must not be the nested item title + assert not result.markdown.startswith("# Item One") + assert "Only desc" in result.markdown + assert "## Item One" in result.markdown + + +def test_rss_no_titles_at_all_does_not_raise(): + """Missing channel title + no item titles previously raised UnboundLocalError.""" + xml = ( + b'' + b"Only desc" + b"body" + b"" + ) + result = RssConverter().convert(io.BytesIO(xml), StreamInfo(extension=".rss")) + assert "Only desc" in result.markdown + assert result.title is None + + +def test_rss_channel_title_still_preferred(): + xml = ( + b'' + b"Feed TitleDesc" + b"Item" + b"" + ) + result = RssConverter().convert(io.BytesIO(xml), StreamInfo(extension=".rss")) + assert result.title == "Feed Title" + assert result.markdown.startswith("# Feed Title") + assert "## Item" in result.markdown + + +def test_atom_missing_feed_title(): + xml = ( + b'' + b"Entry" + b"" + ) + result = RssConverter().convert(io.BytesIO(xml), StreamInfo(extension=".atom")) + assert result.title is None + assert not result.markdown.startswith("# Entry") + assert "## Entry" in result.markdown + + +def test_zip_propagates_keep_data_uris_and_skips_directories(): + html = b'' + buf = io.BytesIO() + with zipfile.ZipFile(buf, "w") as zf: + zf.writestr("folder/", "") + zf.writestr("folder/x.html", html) + buf.seek(0) + + kept = MarkItDown().convert_stream( + buf, stream_info=StreamInfo(extension=".zip"), keep_data_uris=True + ) + assert "data:image/png;base64,aaaa" in kept.markdown + assert "## File: folder/x.html" in kept.markdown + # Directory-only entries must not get their own section heading. + assert "\n## File: folder/\n" not in ("\n" + kept.markdown + "\n") + + buf.seek(0) + truncated = MarkItDown().convert_stream( + buf, stream_info=StreamInfo(extension=".zip"), keep_data_uris=False + ) + assert "data:image/png;base64,aaaa" not in truncated.markdown + assert "data:image" in truncated.markdown + assert "aaaa" not in truncated.markdown + + +if __name__ == "__main__": + test_rss_no_channel_title_does_not_crash_or_leak_item_title() + test_rss_no_titles_at_all_does_not_raise() + test_rss_channel_title_still_preferred() + test_atom_missing_feed_title() + test_zip_propagates_keep_data_uris_and_skips_directories() + print("all passed")