Skip to content

Commit aeb46a7

Browse files
committed
fix: add ZipInfo timestamp clamp to python-agent-driver warm-up
Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent 2dcac69 commit aeb46a7

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

examples/python-agent-driver/hl_pydriver.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,20 @@ static void py_initialize_once(void)
258258
" except Exception as _e:\n"
259259
" sys.stderr.write(f'warn: preload {_mod} failed: {_e}\\n')\n");
260260

261+
/* Monkey-patch zipfile.ZipInfo.__init__ to clamp pre-1980 timestamps.
262+
* Unikraft's ramfs reports epoch-0 (1970) for file mtimes; Python's
263+
* zipfile rejects timestamps before 1980, breaking openpyxl's XLSX
264+
* writer (XLSX is a ZIP container). */
265+
PyRun_SimpleString(
266+
"import zipfile as _zf\n"
267+
"_orig_zi = _zf.ZipInfo.__init__\n"
268+
"def _safe_zi(self, filename='NoName', date_time=(1980,1,1,0,0,0)):\n"
269+
" if date_time[0] < 1980:\n"
270+
" date_time = (1980,1,1,0,0,0)\n"
271+
" _orig_zi(self, filename, date_time)\n"
272+
"_zf.ZipInfo.__init__ = _safe_zi\n"
273+
"del _zf, _orig_zi, _safe_zi\n");
274+
261275
/* Monkey-patch time.sleep to call the host via /dev/hcall.
262276
* Unikraft's cooperative scheduler on Hyperlight has no timer
263277
* interrupt, so the kernel-level nanosleep is a no-op. This

0 commit comments

Comments
 (0)