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 — `hashlib` BLAKE2 `.copy()` crashes with `Py_UNREACHABLE` in `py_blake2_clear` when the copy's allocation fails · Issue #152851 · python/cpython Closed Labels extension-modulesC modules in the Modules dirC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump DescriptionCrash reportWhat happened?
On a debug build this is a deterministic fatal error; on a release build ReproducerThe failing allocation is HACL*'s raw /* oomshim.c: cc -shared -fPIC -O2 -o oomshim.so oomshim.c -ldl * arm_next_malloc() makes the very next malloc() return NULL. */ #define _GNU_SOURCE #include <dlfcn.h> #include <errno.h> #include <stddef.h> #include <string.h> static void *(*real_malloc)(size_t); static void *(*real_calloc)(size_t,size_t); static void (*real_free)(void*); static int armed = 0; static char boot[16384]; static size_t boot_off = 0; static int initing = 0; static int is_boot(const void*p){return (const char*)p>=boot&&(const char*)p<boot+sizeof boot;} static void init_reals(void){ initing=1; real_malloc=dlsym(RTLD_NEXT,"malloc"); real_calloc=dlsym(RTLD_NEXT,"calloc"); real_free=dlsym(RTLD_NEXT,"free"); initing=0; } void arm_next_malloc(void){ armed = 1; } void *malloc(size_t n){ if(!real_malloc){ if(initing){void*p=boot+boot_off;boot_off+=(n+15)&~(size_t)15;return p;} init_reals(); } if(armed){ armed=0; errno=ENOMEM; return NULL; } return real_malloc(n); } void *calloc(size_t a,size_t b){ if(!real_calloc){ if(initing){void*p=boot+boot_off;boot_off+=((a*b)+15)&~(size_t)15;memset(p,0,a*b);return p;} init_reals(); } return real_calloc(a,b); } void free(void*p){ if(is_boot(p))return; if(!real_free)init_reals(); if(real_free)real_free(p); } # repro.py — LD_PRELOAD=./oomshim.so ./python repro.py import ctypes, faulthandler faulthandler.enable() import _blake2 lib = ctypes.CDLL(None) h = _blake2.blake2s(b"data") # (blake2b behaves identically) lib.arm_next_malloc() # next malloc() returns NULL h.copy() # -> Fatal Python error: py_blake2_clear ... Traceback (debug build, gdb)Root cause
Suggested fixInitialize the discriminant (and NULL the state pointer) before the fallible allocation, mirroring cpy->impl = self->impl; /* leave the state pointer NULL until the copy succeeds, so py_blake2_clear is a no-op on error */ (Alternatively, have Environment
Found via allocation-failure fuzzing with fusil, created by @vstinner. The investigation was conducted and this report was drafted with the help of Claude Code (Opus 4.8). CPython versions tested on:CPython main branch Operating systems tested on:Linux Output from running 'python -VV' on the command line:Python 3.16.0a0 (heads/main:1b9fe5c7226, Jun 20 2026, 23:56:12) [Clang 21.1.8 (6ubuntu1)] Linked PRsActivity
MetadataMetadataAssigneesLabelsextension-modulesC modules in the Modules dirC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump 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. |