Issue 22266: fix reliance on refcounting in tarfile.gzopen (original) (raw)

Created on 2014-08-24 20:35 by bdkearns, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tarfile.patch bdkearns,2014-08-25 04:32
tarfile2.patch bdkearns,2014-08-25 15:09
Messages (5)
msg225836 - (view) Author: Brian Kearns (bdkearns) * Date: 2014-08-24 20:35
tarfile.gzopen relies on refcounting to close the fileobj when the fileobj is created during the call to gzopen (when it is not passed in). Since the fileobj is created outside of GzipFile, GzipFile does not take responsibility for closing the fileobj (so no one does, aside from the GC, which leads to unexpected behavior when using a non-refcounted GC). This is fixed by having GzipFile open the fileobj itself, so it does take responsibility for closing it when necessary. The same approach is taken in tarfile.py in py3k branch.
msg225848 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2014-08-24 23:35
I think technically this changes semantics, since the construction of the GzipFile is no longer in the main try-except. You should probably backport the full 3.x behavior.
msg225864 - (view) Author: Brian Kearns (bdkearns) * Date: 2014-08-25 04:32
Yes, I guess that makes sense (though this behavior is undocumented and untested...)
msg225876 - (view) Author: Brian Kearns (bdkearns) * Date: 2014-08-25 14:52
Updated to backport all the cases where 3.x handles this issue.
msg226007 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-08-28 00:31
New changeset 6f0dae921bee by Benjamin Peterson in branch '2.7': properly handle file closing in error cases (closes #22266) http://hg.python.org/cpython/rev/6f0dae921bee
History
Date User Action Args
2022-04-11 14:58:07 admin set github: 66462
2014-08-28 00:31:49 python-dev set status: open -> closednosy: + python-devmessages: + resolution: fixedstage: resolved
2014-08-25 15:09:56 bdkearns set files: + tarfile2.patch
2014-08-25 15:09:49 bdkearns set files: - tarfile2.patch
2014-08-25 14:52:32 bdkearns set files: + tarfile2.patchmessages: +
2014-08-25 04:32:27 bdkearns set files: + tarfile.patchmessages: +
2014-08-25 04:31:29 bdkearns set files: - tarfile.patch
2014-08-24 23:35:22 benjamin.peterson set nosy: + benjamin.petersonmessages: +
2014-08-24 20:45:42 alex set nosy: + alex
2014-08-24 20:35:11 bdkearns create