GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — `mailbox.MH.__setitem__()` can destroy a message when replacement fails · Issue #156312 · python/cpython Open Labels stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-emailtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionBug description:Summary`When mailbox.MH replaces an existing message with an invalid str, it correctly raises ValueError, but the original message file may already have been truncated to empty. In other words, the replacement fails while also destroying the existing message content, resulting in data loss. Affected public API: Minimal reproducerRun this against CPython before the fix: import mailbox import tempfile with tempfile.TemporaryDirectory() as path: box = mailbox.MH(path) key = box.add(b"Subject: original\n\noriginal body\n") original = box.get_bytes(key) try: box[key] = "Subject: caf\u00e9\n\nreplacement body\n" except ValueError as exc: print(type(exc).__name__, exc) print("in-memory:", box.get_bytes(key)) box.close() reopened = mailbox.MH(path) print("reopened:", reopened.get_bytes(key)) assert reopened.get_bytes(key) == original Actual result before the fix: Expected result: The same problem occurs if a file-like message object raises while it is being read: the old message is replaced with the bytes written before the exception. Root cause
CPython versions tested on:CPython main branch Operating systems tested on:Linux Linked PRsActivity
MetadataMetadataAssigneesLabelsstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-emailtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |