Commit 7352b6a
authored
Since GH-157861, every writer uses the read-only optimization of
_PyUnicodeWriter_WriteStr(), so the first write of a str subclass
instance into an empty writer kept that object as the buffer, and
PyUnicodeWriter_Finish() returned it. io.StringIO.getvalue() then
returned the written object itself, and the next write re-read it
through its __str__() method, which changed the contents and could make
read() read past the end of the buffer.
Only use the read-only optimization for exact str objects. A subclass
is copied into a new buffer, as before GH-157861.
1 parent 4e9ea68 commit 7352b6a
3 files changed
Lines changed: 18 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1910 | 1910 | | |
1911 | 1911 | | |
1912 | 1912 | | |
| 1913 | + | |
| 1914 | + | |
| 1915 | + | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
| 1924 | + | |
1913 | 1925 | | |
1914 | 1926 | | |
1915 | 1927 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1118 | 1118 | | |
1119 | 1119 | | |
1120 | 1120 | | |
1121 | | - | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
1122 | 1126 | | |
1123 | 1127 | | |
1124 | 1128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
316 | | - | |
| 316 | + | |
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
| |||
0 commit comments