mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-07 10:20:29 +00:00
fix issue pointed out by ubsan warning
instead of reading the FILE* in little parts via PyMarshal_ReadObjectFromFile, now I just load the whole file into memory and call PyMarshal_ReadObjectFromString instead. This prevents ubsan warnings.
This commit is contained in:
parent
ea2a5ffd6c
commit
0632853206
1 changed files with 11 additions and 1 deletions
12
third_party/python/Python/import.c
vendored
12
third_party/python/Python/import.c
vendored
|
@ -2436,6 +2436,8 @@ static PyObject *SFLObject_get_code(SourcelessFileLoader *self, PyObject *arg) {
|
|||
char *name = NULL;
|
||||
FILE *fp = NULL;
|
||||
PyObject *res = NULL;
|
||||
char *rawbuf = NULL;
|
||||
size_t rawlen = 0;
|
||||
|
||||
if (!PyArg_Parse(arg, "z:get_code", &name)) return 0;
|
||||
if (!name) name = self->name;
|
||||
|
@ -2472,8 +2474,16 @@ static PyObject *SFLObject_get_code(SourcelessFileLoader *self, PyObject *arg) {
|
|||
goto exit;
|
||||
}
|
||||
// return _compile_bytecode(bytes_data, name=fullname, bytecode_path=path)
|
||||
if (!(res = PyMarshal_ReadObjectFromFile(fp))) goto exit;
|
||||
rawlen = stinfo.st_size - headerlen;
|
||||
rawbuf = PyMem_RawMalloc(rawlen);
|
||||
if (rawlen != fread(rawbuf, sizeof(char), rawlen, fp)) {
|
||||
PyErr_Format(PyExc_ImportError, "reached EOF while size of source in %s\n",
|
||||
name);
|
||||
goto exit;
|
||||
}
|
||||
if (!(res = PyMarshal_ReadObjectFromString(rawbuf, rawlen))) goto exit;
|
||||
exit:
|
||||
if (rawbuf) PyMem_RawFree(rawbuf);
|
||||
if (fp) fclose(fp);
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue