python / python/cpython

obmalloc debug info can produce invalidly encoded output

Open
#95,574 2 comments 0 reactions 1 assignee View on GitHub

@vstinner is already working on this.

Since Aug 2, 2022.

interpreter-core type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

obmalloc's debug mode (specifically _PyMem_DebugCheckAddress() and _PyObject_DebugDumpAddress()) can produce output that is invalid in the text encoding being used by the process. This is because it prints the api_id byte to stderr with fprintf() using the %c format, and the byte can be corrupted. Because of the nature of these checks (they try to prevent memory corruption) it is actually fairly likely that the byte is corrupted, which can mean the output can't then be easily handled by tooling that expects a specific encoding (like UTF-8).

It would probably make sense to check whether the value of the api_id is a printable ASCII character before trying to print it, and resort to printing the value with %x instead.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.