Skip to content

Commit 6fd502f

Browse files
authored
Merge branch 'main' into fix-issueissue-162341
2 parents c3968b8 + 31ed3ef commit 6fd502f

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎Doc/library/tempfile.rst‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ The module defines the following user-callable items:
107107
The latter approach is recommended as it provides assistance in automatic
108108
cleaning of the temporary file upon the context manager exit.
109109

110+
.. warning::
111+
112+
Reopening the temporary file by name is only safe when the file's
113+
directory is trusted. See :cwe:`377` for more information.
114+
110115
Opening the temporary file again by its name while it is still open works as
111116
follows:
112117

@@ -451,6 +456,7 @@ Here are some examples of typical usage of the :mod:`!tempfile` module::
451456

452457
# create a temporary file using a context manager
453458
# close the file, use the name to open the file again
459+
# this is only safe if the directory cannot be modified by untrusted users
454460
>>> with tempfile.NamedTemporaryFile(delete_on_close=False) as fp:
455461
... fp.write(b'Hello world!')
456462
... fp.close()

‎Objects/mimalloc/arena-abandon.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,14 @@ void _mi_arena_segment_mark_abandoned(mi_segment_t* segment)
154154
mi_arena_memid_indices(segment->memid, &arena_idx, &bitmap_idx);
155155
mi_arena_t* arena = mi_arena_from_index(arena_idx);
156156
mi_assert_internal(arena != NULL);
157+
// CPython: gh-162484: check before marking; once the segment is marked
158+
// abandoned another thread can reclaim and free it.
159+
mi_assert_internal(_mi_bitmap_is_claimed(arena->blocks_inuse, arena->field_count, 1, bitmap_idx));
157160
// set abandonment atomically
158161
mi_subproc_t* const subproc = segment->subproc; // don't access the segment after setting it abandoned
159162
const bool was_unmarked = _mi_bitmap_claim(arena->blocks_abandoned, arena->field_count, 1, bitmap_idx, NULL);
160163
if (was_unmarked) { mi_atomic_increment_relaxed(&subproc->abandoned_count); }
161164
mi_assert_internal(was_unmarked);
162-
mi_assert_internal(_mi_bitmap_is_claimed(arena->blocks_inuse, arena->field_count, 1, bitmap_idx));
163165
}
164166

165167

0 commit comments

Comments
 (0)