gh-108111: Flush gzip write buffer before seeking, fixing bad writes (#108341)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
Chris Markiewicz 2023-08-24 04:23:01 -04:00 committed by GitHub
parent aa9a359ca2
commit 2eb60c1934
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 0 deletions

View file

@ -401,6 +401,9 @@ class GzipFile(_compression.BaseStream):
def seek(self, offset, whence=io.SEEK_SET):
if self.mode == WRITE:
self._check_not_closed()
# Flush buffer to ensure validity of self.offset
self._buffer.flush()
if whence != io.SEEK_SET:
if whence == io.SEEK_CUR:
offset = self.offset + offset