8000 gh-111178: fix UBSan failures in `Modules/cjkcodecs/multibytecodec.c` by picnixz · Pull Request #129090 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111178: fix UBSan failures in Modules/cjkcodecs/multibytecodec.c #129090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Move cast macros to .c
  • Loading branch information
picnixz committed Jan 20, 2025
commit 97cd79b1a127b1594ab2ddf1bd19063733ec0e4e
21 changes: 21 additions & 0 deletions Modules/cjkcodecs/multibytecodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ class _multibytecodec.MultibyteStreamWriter "MultibyteStreamWriterObject *" "cli
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=305a76dfdd24b99c]*/
#undef clinic_get_state

#define _MultibyteCodec_CAST(op) ((MultibyteCodec *)(op))
#define _MultibyteCodecObject_CAST(op) ((MultibyteCodecObject *)(op))

#define _MultibyteStatefulCodecContext_CAST(op) \
((MultibyteStatefulCodecContext *)(op))

#define _MultibyteStatefulEncoderContext_CAST(op) \
((MultibyteStatefulEncoderContext *)(op))
#define _MultibyteStatefulDecoderContext_CAST(op) \
((MultibyteStatefulDecoderContext *)(op))

#define _MultibyteIncrementalEncoderObject_CAST(op) \
((MultibyteIncrementalEncoderObject *)(op))
#define _MultibyteIncrementalDecoderObject_CAST(op) \
((MultibyteIncrementalDecoderObject *)(op))

#define _MultibyteStreamReaderObject_CAST(op) \
((MultibyteStreamReaderObject *)(op))
#define _MultibyteStreamWriterObject_CAST(op) \
((MultibyteStreamWriterObject *)(op))

typedef struct {
PyObject *inobj;
Py_ssize_t inpos, inlen;
Expand Down
17 changes: 0 additions & 17 deletions Modules/cjkcodecs/multibytecodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,21 @@ typedef struct {
PyObject *cjk_module;
} MultibyteCodecObject;

#define _MultibyteCodec_CAST(op) ((MultibyteCodec *)(op))
#define _MultibyteCodecObject_CAST(op) ((MultibyteCodecObject *)(op))
#define MultibyteCodec_Check(state, op) Py_IS_TYPE((op), state->multibytecodec_type)

#define _MultibyteStatefulCodec_HEAD \
PyObject_HEAD \
const MultibyteCodec *codec; \
MultibyteCodec_State state; \
PyObject *errors;

typedef struct {
_MultibyteStatefulCodec_HEAD
} MultibyteStatefulCodecContext;

#define _MultibyteStatefulCodecContext_CAST(op) \
((MultibyteStatefulCodecContext *)(op))

#define MAXENCPENDING 2
#define _MultibyteStatefulEncoder_HEAD \
_MultibyteStatefulCodec_HEAD \
PyObject *pending;

typedef struct {
_MultibyteStatefulEncoder_HEAD
} MultibyteStatefulEncoderContext;
Expand All @@ -103,14 +96,10 @@ typedef struct {
_MultibyteStatefulCodec_HEAD \
unsigned char pending[MAXDECPENDING]; \
Py_ssize_t pendingsize;

typedef struct {
_MultibyteStatefulDecoder_HEAD
} MultibyteStatefulDecoderContext;

#define _MultibyteStatefulEncoderContext_CAST(op) ((MultibyteStatefulEncoderContext *)(op))
#define _MultibyteStatefulDecoderContext_CAST(op) ((MultibyteStatefulDecoderContext *)(op))

typedef struct {
_MultibyteStatefulEncoder_HEAD
} MultibyteIncrementalEncoderObject;
Expand All @@ -119,9 +108,6 @@ typedef struct {
_MultibyteStatefulDecoder_HEAD
} MultibyteIncrementalDecoderObject;

#define _MultibyteIncrementalEncoderObject_CAST(op) ((MultibyteIncrementalEncoderObject *)(op))
#define _MultibyteIncrementalDecoderObject_CAST(op) ((MultibyteIncrementalDecoderObject *)(op))

typedef struct {
_MultibyteStatefulDecoder_HEAD
PyObject *stream;
Expand All @@ -132,9 +118,6 @@ typedef struct {
PyObject *stream;
} MultibyteStreamWriterObject;

#define _MultibyteStreamReaderObject_CAST(op) ((MultibyteStreamReaderObject *)(op))
#define _MultibyteStreamWriterObject_CAST(op) ((MultibyteStreamWriterObject *)(op))

/* positive values for illegal sequences */
#define MBERR_TOOSMALL (-1) /* insufficient output buffer space */
#define MBERR_TOOFEW (-2) /* incomplete input buffer */
Expand Down
Loading
0