mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-129726: Break gzip.GzipFile
reference loop (#130055)
A reference loop was resulting in the `fileobj` held by the `GzipFile` being closed before the `GzipFile`. The issue started with gh-89550 in 3.12, but was hidden in most cases until 3.13 when gh-62948 made it more visible.
This commit is contained in:
parent
e41981704f
commit
7f39137662
3 changed files with 28 additions and 5 deletions
17
Lib/gzip.py
17
Lib/gzip.py
|
@ -5,11 +5,15 @@ but random access is not allowed."""
|
|||
|
||||
# based on Andrew Kuchling's minigzip.py distributed with the zlib module
|
||||
|
||||
import struct, sys, time, os
|
||||
import zlib
|
||||
import _compression
|
||||
import builtins
|
||||
import io
|
||||
import _compression
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
import time
|
||||
import weakref
|
||||
import zlib
|
||||
|
||||
__all__ = ["BadGzipFile", "GzipFile", "open", "compress", "decompress"]
|
||||
|
||||
|
@ -125,10 +129,13 @@ class BadGzipFile(OSError):
|
|||
class _WriteBufferStream(io.RawIOBase):
|
||||
"""Minimal object to pass WriteBuffer flushes into GzipFile"""
|
||||
def __init__(self, gzip_file):
|
||||
self.gzip_file = gzip_file
|
||||
self.gzip_file = weakref.ref(gzip_file)
|
||||
|
||||
def write(self, data):
|
||||
return self.gzip_file._write_raw(data)
|
||||
gzip_file = self.gzip_file()
|
||||
if gzip_file is None:
|
||||
raise RuntimeError("lost gzip_file")
|
||||
return gzip_file._write_raw(data)
|
||||
|
||||
def seekable(self):
|
||||
return False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue