File tree 5 files changed +54
-0
lines changed
5 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ def file_move_safe(
55
55
| os .O_CREAT
56
56
| getattr (os , "O_BINARY" , 0 )
57
57
| (os .O_EXCL if not allow_overwrite else 0 )
58
+ | os .O_TRUNC
58
59
),
59
60
)
60
61
try :
Original file line number Diff line number Diff line change
1
+ ===========================
2
+ Django 4.2.21 release notes
3
+ ===========================
4
+
5
+ *Expected May 7, 2025*
6
+
7
+ Django 4.2.21 fixes a data loss bug in 4.2.20.
8
+
9
+ Bugfixes
10
+ ========
11
+
12
+ * Fixed a data corruption possibility in ``file_move_safe()`` when
13
+ ``allow_overwrite=True``, where leftover content from a previously larger
14
+ file could remain after overwriting with a smaller one due to lack of
15
+ truncation (:ticket:`36298`).
Original file line number Diff line number Diff line change
1
+ ==========================
2
+ Django 5.1.9 release notes
3
+ ==========================
4
+
5
+ *Expected May 7, 2025*
6
+
7
+ Django 5.1.9 fixes a data loss bug in 5.1.8.
8
+
9
+ Bugfixes
10
+ ========
11
+
12
+ * Fixed a data corruption possibility in ``file_move_safe()`` when
13
+ ``allow_overwrite=True``, where leftover content from a previously larger
14
+ file could remain after overwriting with a smaller one due to lack of
15
+ truncation (:ticket:`36298`).
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ versions of the documentation contain the release notes for any later releases.
25
25
.. toctree::
26
26
:maxdepth: 1
27
27
28
+ 5.1.9
28
29
5.1.8
29
30
5.1.7
30
31
5.1.6
@@ -62,6 +63,7 @@ versions of the documentation contain the release notes for any later releases.
62
63
.. toctree::
63
64
:maxdepth: 1
64
65
66
+ 4.2.21
65
67
4.2.20
66
68
4.2.19
67
69
4.2.18
Original file line number Diff line number Diff line change @@ -496,6 +496,27 @@ def test_file_move_permissionerror(self):
496
496
os .close (handle_b )
497
497
os .close (handle_c )
498
498
499
+ def test_file_move_ensure_truncation (self ):
500
+ with tempfile .NamedTemporaryFile (delete = False ) as src :
501
+ src .write (b"content" )
502
+ src_name = src .name
503
+ self .addCleanup (
504
+ lambda : os .remove (src_name ) if os .path .exists (src_name ) else None
505
+ )
506
+
507
+ with tempfile .NamedTemporaryFile (delete = False ) as dest :
508
+ dest .write (b"This is a longer content." )
509
+ dest_name = dest .name
510
+ self .addCleanup (os .remove , dest_name )
511
+
512
+ with mock .patch ("django.core.files.move.os.rename" , side_effect = OSError ()):
513
+ file_move_safe (src_name , dest_name , allow_overwrite = True )
514
+
515
+ with open (dest_name , "rb" ) as f :
516
+ content = f .read ()
517
+
518
+ self .assertEqual (content , b"content" )
519
+
499
520
500
521
class SpooledTempTests (unittest .TestCase ):
501
522
def test_in_memory_spooled_temp (self ):
You can’t perform that action at this time.
0 commit comments