Commit 955f1fc
committed
gh-151046: Fix use-after-free in _Unpickler_ReadIntoFromFile
When unpickling from a file-like object that provides readinto(), the C
Unpickler handed it a temporary memoryview over an internal buffer and never
released it. A readinto() implementation that kept a reference to the view
could read or write the buffer after it had been freed, a use-after-free
reachable from pure Python.
Keep an owned reference across the call and release the memoryview as soon as
readinto() returns, so a surviving reference raises ValueError instead of
dereferencing freed memory. Add a regression test.1 parent 5755d0f commit 955f1fc
3 files changed
Lines changed: 97 additions & 2 deletions
File tree
- Lib/test
- Misc/NEWS.d/next/Library
- Modules
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
382 | 382 | | |
383 | 383 | | |
384 | 384 | | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
385 | 432 | | |
386 | 433 | | |
387 | 434 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1283 | 1283 | | |
1284 | 1284 | | |
1285 | 1285 | | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
1286 | 1312 | | |
1287 | 1313 | | |
1288 | 1314 | | |
| |||
1318 | 1344 | | |
1319 | 1345 | | |
1320 | 1346 | | |
1321 | | - | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
1322 | 1356 | | |
1323 | 1357 | | |
1324 | 1358 | | |
1325 | 1359 | | |
1326 | | - | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
1327 | 1364 | | |
| 1365 | + | |
1328 | 1366 | | |
1329 | 1367 | | |
1330 | 1368 | | |
1331 | 1369 | | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
1332 | 1373 | | |
1333 | 1374 | | |
1334 | 1375 | | |
| |||
0 commit comments