Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

_csv:_set_str() missing NULL check afterPyUnicode_DecodeASCII() #145978

Closed as duplicate of#146093
Labels
extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error
@raminfp

Description

@raminfp

Bug report

Bug description:

InModules/_csv.c,_set_str() does not check the return value ofPyUnicode_DecodeASCII() when using the default value. If the allocation fails (OOM),*target is set toNULL and the function returns0 (success).

https://github.com/python/cpython/blob/main/Modules/_csv.c#L315-L329

staticint_set_str(constchar*name,PyObject**target,PyObject*src,constchar*dflt){if (src==NULL)*target=PyUnicode_DecodeASCII(dflt,strlen(dflt),NULL);// ^^^ no NULL checkelse {        ...    }return0;// Returns 0 even if allocation failed}

This function is called forlineterminator:

DIASET(_set_str,"lineterminator",&self->lineterminator,lineterminator,"\r\n");

If allocation fails,self->lineterminator isNULL. Subsequent calls toPyUnicode_GET_LENGTH(dialect->lineterminator) (e.g. injoin_append_data at line 1183 orjoin_append_lineterminator at line 1299) will dereferenceNULL.

Fix

staticint_set_str(constchar*name,PyObject**target,PyObject*src,constchar*dflt){if (src==NULL) {*target=PyUnicode_DecodeASCII(dflt,strlen(dflt),NULL);if (*target==NULL)return-1;    }else {if (!PyUnicode_Check(src)) {PyErr_Format(PyExc_TypeError,"\"%s\" must be a string, not %T",name,src);return-1;        }Py_XSETREF(*target,Py_NewRef(src));    }return0;}

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp