Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

- Fixed: `markfind import` crashed with a traceback on a property list whose
XML declaration named an unknown encoding. It is now reported like any other
unreadable file. Found by fuzzing the parsers (#78).

- Fixed: a bookmark pointing at a page that only redirects, through
`<meta http-equiv="refresh">`, was indexed as the stub. One real example
indexed 28 characters of "Click here to be redirected." instead of the
Expand Down
9 changes: 8 additions & 1 deletion src/markfind/importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,14 @@ def parse_safari_plist(data: bytes) -> list[Bookmark]:
"""Parse Safari's ``Bookmarks.plist`` (binary or XML property list)."""
try:
root = plistlib.loads(data)
except (plistlib.InvalidFileException, ExpatError, ValueError, OverflowError) as exc:
# LookupError: the XML declaration names an encoding Python doesn't have.
except (
plistlib.InvalidFileException,
ExpatError,
ValueError,
OverflowError,
LookupError,
) as exc:
raise ValueError(f"not a readable Safari bookmarks file: {exc}") from exc
if not isinstance(root, dict):
raise ValueError("not a readable Safari bookmarks file: unexpected contents")
Expand Down
9 changes: 9 additions & 0 deletions tests/test_safari.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def test_load_file_detects_plists(tmp_path, fmt):
[
b"bplist00 this is not really a binary plist",
b'<?xml version="1.0"?><plist version="1.0"><dict><key>x</key>',
# An encoding Python doesn't have: plistlib raises LookupError, not ValueError.
b'<?xml version="1.0" encoding="zTF-8"?><plist version="1.0"><dict/></plist>',
plistlib.dumps(["a list, not a dict"]),
],
)
Expand All @@ -101,6 +103,13 @@ def test_binary_plist_written_by_apples_own_tool(tmp_path):
assert load_file(path) == EXPECTED


def test_a_corrupt_plist_file_is_reported_not_raised(tmp_path, capsys):
path = tmp_path / "Bookmarks.plist"
path.write_bytes(b'<?xml version="1.0" encoding="zTF-8"?><plist><dict/></plist>')
assert cli.main(["--db", str(tmp_path / "db.sqlite"), "import", str(path)]) == 1
assert "could not read" in capsys.readouterr().err


def test_other_formats_still_detected(tmp_path):
html = tmp_path / "export.html"
html.write_text('<DT><A HREF="https://a.example/">A</A>', encoding="utf-8")
Expand Down
Loading