diff --git a/examples/python-agent-driver/hl_pydriver.c b/examples/python-agent-driver/hl_pydriver.c index 9668938..16c8266 100644 --- a/examples/python-agent-driver/hl_pydriver.c +++ b/examples/python-agent-driver/hl_pydriver.c @@ -265,13 +265,15 @@ static void py_initialize_once(void) * writer (XLSX is a ZIP container). */ PyRun_SimpleString( "import zipfile as _zf\n" - "_orig_zi = _zf.ZipInfo.__init__\n" - "def _safe_zi(self, filename='NoName', date_time=(1980,1,1,0,0,0)):\n" - " if date_time[0] < 1980:\n" - " date_time = (1980,1,1,0,0,0)\n" - " _orig_zi(self, filename, date_time)\n" - "_zf.ZipInfo.__init__ = _safe_zi\n" - "del _zf, _orig_zi, _safe_zi\n"); + "def _patch_zipinfo():\n" + " _orig = _zf.ZipInfo.__init__\n" + " def _safe(self, filename='NoName', date_time=(1980,1,1,0,0,0)):\n" + " if date_time[0] < 1980:\n" + " date_time = (1980,1,1,0,0,0)\n" + " _orig(self, filename, date_time)\n" + " _zf.ZipInfo.__init__ = _safe\n" + "_patch_zipinfo()\n" + "del _patch_zipinfo, _zf\n"); /* Monkey-patch time.sleep to call the host via /dev/hcall. * Unikraft's cooperative scheduler on Hyperlight has no timer diff --git a/host/tests/pyhl_runtime.rs b/host/tests/pyhl_runtime.rs index 20b371a..15e9fb6 100644 --- a/host/tests/pyhl_runtime.rs +++ b/host/tests/pyhl_runtime.rs @@ -117,6 +117,21 @@ fn runtime_pandas_import() { assert_eq!(timing.exit_code, 0); } +// --------------------------------------------------------------------------- +// zipfile.ZipInfo monkey-patch (pre-1980 date clamping) +// --------------------------------------------------------------------------- + +#[test] +fn runtime_zipinfo_patch_survives_cleanup() { + let Some((_home, mut rt)) = setup() else { + return; + }; + let timing = rt + .run_code("from docx import Document\ndoc = Document()\nprint('ok')") + .unwrap(); + assert_eq!(timing.exit_code, 0); +} + // --------------------------------------------------------------------------- // Exit code propagation // ---------------------------------------------------------------------------