The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: cover remaining anydoc-extracted container formats
kshitij5c988e246198
diff --git a/tests/tools/test_binary_document_write_guard.py b/tests/tools/test_binary_document_write_guard.pyindex 3bb95d40f5e..dff0cefd3a2 100644--- a/tests/tools/test_binary_document_write_guard.py+++ b/tests/tools/test_binary_document_write_guard.py@@ -40,8 +40,10 @@ def _make_minimal_docx(path: Path) -> None:class TestExtensionHelpers:def test_opaque_document_extensions(self):- for p in ("a.docx", "b.XLSX", "c.pptx", "d.doc", "e.odt", "f.ods", "g.odp"):- assert has_opaque_document_extension(p) is True+ for p in ("a.docx", "b.XLSX", "c.pptx", "d.doc", "e.odt", "f.ods", "g.odp",+ "h.docm", "i.xlsm", "j.xlsb", "k.pptm", "l.ppsx", "m.ppsm",+ "n.pps", "o.pot", "p.rtf", "q.epub"):+ assert has_opaque_document_extension(p) is True, f"{p} should be opaque"def test_non_opaque_paths(self):for p in ("a.txt", "b.py", "c.pdf", "d.md", "noext", "e.csv"):@@ -86,6 +88,20 @@ class TestWriteFileToolGuard:assert docx.read_bytes() == original, "document bytes must be untouched"assert zipfile.is_zipfile(docx), "document must remain a valid container"+ def test_write_file_rejects_docm(self, tmp_path: Path):+ """Regression: .docm is extractable by read_file (anydoc) but was+ missing from OPAQUE_DOCUMENT_EXTENSIONS in the original PR #82818.+ Flagged by @egilewski — proven live: text write corrupted the zip."""+ docm = tmp_path / "macro.docm"+ _make_minimal_docx(docm) # same OOXML zip structure+ original = docm.read_bytes()++ result = json.loads(write_file_tool(str(docm), "edited text"))++ assert result.get("error"), "text write into .docm must be refused"+ assert docm.read_bytes() == original, "document bytes must be untouched"+ assert zipfile.is_zipfile(docm), "document must remain a valid container"+def test_write_file_rejects_new_docx(self, tmp_path: Path):result = json.loads(write_file_tool(str(tmp_path / "new.docx"), "hello"))assert result.get("error")diff --git a/tools/binary_extensions.py b/tools/binary_extensions.pyindex 17147be80f7..5eac3d0d75d 100644--- a/tools/binary_extensions.py+++ b/tools/binary_extensions.py@@ -42,16 +42,20 @@ def has_binary_extension(path: str) -> bool:return path[dot:].lower() in BINARY_EXTENSIONS-# Container document formats (OOXML zip / OLE compound / ODF zip) that a-# plain-text write can NEVER produce validly. read_file auto-extracts these-# to readable text, so a model that "read" report.docx and then writes the-# edited text back via write_file/patch silently destroys the document.+# Container document formats (OOXML zip / OLE compound / ODF zip / EPUB zip / RTF)+# that a plain-text write can NEVER produce validly. read_file auto-extracts+# these to readable text (via anydoc for the non-built-in formats), so a model+# that "read" report.docx and then writes the edited text back via+# write_file/patch silently destroys the document.# PDF is intentionally NOT here: raw PDF syntax is text-authorable, so# new-file creation is legitimate — only overwrites are dangerous (handled# separately by the write guard).OPAQUE_DOCUMENT_EXTENSIONS = frozenset({- ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx",+ ".doc", ".docx", ".docm",+ ".xls", ".xlsx", ".xlsm", ".xlsb",+ ".ppt", ".pps", ".pot", ".pptx", ".pptm", ".ppsx", ".ppsm",".odt", ".ods", ".odp",+ ".rtf", ".epub",})