Skip to content

Commit c01ed73

Browse files
Additional fixes
1 parent 2e1fb0e commit c01ed73

5 files changed

Lines changed: 19 additions & 8 deletions

File tree

‎.github/workflows/reusable-san.yml‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,11 @@ jobs:
7575
echo "MSAN_OPTIONS=${SAN_LOG_OPTION} allocator_may_return_null=1" >> "$GITHUB_ENV"
7676
# MSan reports false positives for memory initialized by libraries
7777
# that are not built with MSan, so disable modules that use them.
78-
# _remote_debugging is disabled because it links to libzstd directly.
78+
# _remote_debugging links to libzstd directly, but we unpoision the memory.
7979
{
8080
echo '*disabled*'
8181
echo '_bz2 _ctypes _curses _curses_panel _dbm _decimal _gdbm _hashlib'
82-
echo '_lzma _remote_debugging _sqlite3 _ssl _tkinter _uuid _zstd'
83-
echo 'readline zlib'
82+
echo '_lzma _sqlite3 _ssl _tkinter _uuid _zstd readline zlib'
8483
} > Modules/Setup.local
8584
env:
8685
SAN_LOG_OPTION: log_path=${{ github.workspace }}/san_log
@@ -108,6 +107,8 @@ jobs:
108107
# gh-157958: -O2 instead of the pydebug default -Og to avoid a clang 21
109108
# compile-time blowup on some interpreter files.
110109
# (https://github.com/llvm/llvm-project/issues/179695)
110+
# MSan uses --with-assertions instead of --with-pydebug because its
111+
# hooks on the Python memory allocators hide uninitialized reads.
111112
- name: Configure CPython
112113
run: >-
113114
./configure
@@ -120,7 +121,7 @@ jobs:
120121
&& '--with-memory-sanitizer'
121122
|| '--with-undefined-behavior-sanitizer --with-strict-overflow'
122123
}}
123-
--with-pydebug
124+
${{ inputs.sanitizer == 'MSan' && '--with-assertions' || '--with-pydebug' }}
124125
${{ inputs.sanitizer == 'TSan' && '--with-openssl="$OPENSSL_DIR" --with-openssl-rpath=auto' || '' }}
125126
${{ inputs.free-threading && '--disable-gil' || '' }}
126127
- name: Build CPython

‎Lib/test/test_asyncio/test_tools.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import unittest
22

3-
from test.support import import_helper
4-
5-
_remote_debugging = import_helper.import_module('_remote_debugging')
6-
73
from asyncio import tools
84

5+
import _remote_debugging
6+
97

108
def LocationInfo(lineno, end_lineno=None, col_offset=None, end_col_offset=None):
119
return _remote_debugging.LocationInfo((lineno, end_lineno, col_offset, end_col_offset))

‎Modules/_remote_debugging/binary_io_reader.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include <zstd.h>
2020
#endif
2121

22+
#ifdef _Py_MEMORY_SANITIZER
23+
# include <sanitizer/msan_interface.h>
24+
#endif
25+
2226
/* ============================================================================
2327
* CONSTANTS FOR BINARY FORMAT SIZES
2428
* ============================================================================ */
@@ -315,6 +319,7 @@ reader_decompress_samples(BinaryReader *reader, const uint8_t *data)
315319
return -1;
316320
}
317321

322+
_Py_MSAN_UNPOISON(output.dst, output.pos);
318323
total_output += output.pos;
319324
}
320325

‎Modules/_remote_debugging/binary_io_writer.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include <zstd.h>
2020
#endif
2121

22+
#ifdef _Py_MEMORY_SANITIZER
23+
# include <sanitizer/msan_interface.h>
24+
#endif
25+
2226
/* ============================================================================
2327
* CONSTANTS FOR BINARY FORMAT SIZES
2428
* ============================================================================ */
@@ -235,6 +239,7 @@ writer_flush_buffer(BinaryWriter *writer)
235239
return -1;
236240
}
237241

242+
_Py_MSAN_UNPOISON(writer->zstd.compressed_buffer, output.pos);
238243
if (output.pos > 0) {
239244
if (fwrite_checked_allow_threads(writer->zstd.compressed_buffer, output.pos, writer->fp) < 0) {
240245
return -1;
@@ -1084,6 +1089,7 @@ binary_writer_finalize(BinaryWriter *writer)
10841089
return -1;
10851090
}
10861091

1092+
_Py_MSAN_UNPOISON(writer->zstd.compressed_buffer, output.pos);
10871093
if (output.pos > 0) {
10881094
if (fwrite_checked_allow_threads(writer->zstd.compressed_buffer, output.pos, writer->fp) < 0) {
10891095
return -1;

‎Python/instrumentation.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,6 +1690,7 @@ allocate_instrumentation_data(PyCodeObject *code)
16901690
}
16911691
monitoring->local_monitors = (_Py_LocalMonitors){ 0 };
16921692
monitoring->active_monitors = (_Py_LocalMonitors){ 0 };
1693+
memset(monitoring->tool_versions, 0, sizeof(monitoring->tool_versions));
16931694
monitoring->tools = NULL;
16941695
monitoring->lines = NULL;
16951696
monitoring->line_tools = NULL;

0 commit comments

Comments
 (0)