Title: GzipFile.flush doesn't flush compressor in 3.12 beta · Issue #105808 · python/cpython · GitHub
Open Graph Title: GzipFile.flush doesn't flush compressor in 3.12 beta · Issue #105808 · python/cpython
X Title: GzipFile.flush doesn't flush compressor in 3.12 beta · Issue #105808 · python/cpython
Description: Bug report The change to add buffering to GzipFile.write (gh-89550, #101251) broke the GzipFile.flush method. The flush method previously called self.compress.flush, but now it only flushes the IO objects and not the compressor (as a sid...
Open Graph Description: Bug report The change to add buffering to GzipFile.write (gh-89550, #101251) broke the GzipFile.flush method. The flush method previously called self.compress.flush, but now it only flushes the IO ...
X Description: Bug report The change to add buffering to GzipFile.write (gh-89550, #101251) broke the GzipFile.flush method. The flush method previously called self.compress.flush, but now it only flushes the IO ...
Opengraph URL: https://github.com/python/cpython/issues/105808
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"GzipFile.flush doesn't flush compressor in 3.12 beta","articleBody":"\u003c!--\r\n If you're new to Python and you're not sure whether what you're experiencing is a bug, the CPython issue tracker is not\r\n the right place to seek help. Consider the following options instead:\r\n\r\n - reading the Python tutorial: https://docs.python.org/3/tutorial/\r\n - posting in the \"Users\" category on discuss.python.org: https://discuss.python.org/c/users/7\r\n - emailing the Python-list mailing list: https://mail.python.org/mailman/listinfo/python-list\r\n - searching our issue tracker (https://github.com/python/cpython/issues) to see if\r\n your problem has already been reported\r\n--\u003e\r\n\r\n# Bug report\r\n\r\nThe change to add buffering to `GzipFile.write` (gh-89550, #101251) broke the `GzipFile.flush` method. The flush method previously called `self.compress.flush`, but now it only flushes the IO objects and not the compressor (as a side effect, the zlib_mode argument is now ignored, although in my case I only use the default). Flushing the compressor is necessary to create synchronization points that can be used to decompress part of the stream. \r\n\r\nHere is a test script, reduced from Tornado's use of GzipFile (see tornadoweb/tornado#3278 for the way this manifests in Tornado's test suite):\r\n\r\n```python\r\nimport io\r\nimport gzip\r\nimport zlib\r\n\r\n# Write two chunks to the same compressed stream. In real usage\r\n# I send these chunks as two separate network messages, but in this\r\n# test I just save them to two local variables.\r\ndata = io.BytesIO()\r\ngzip_file = gzip.GzipFile(fileobj=data, mode=\"wb\")\r\ngzip_file.write(b\"Hello World\")\r\ngzip_file.flush()\r\nmessage1 = data.getvalue()\r\ndata.truncate(0)\r\ndata.seek(0)\r\ngzip_file.write(b\"Goodbye World\")\r\ngzip_file.close()\r\nmessage2 = data.getvalue()\r\n\r\n# Decode the two messages. Each one should decode separately,\r\n# but in Python 3.12b2 the compressor was not flushed with\r\n# Z_SYNC_FLUSH so the second message produces no output on its own\r\n# and both messages are emitted when the second message is added\r\n# to the decompressor's input.\r\n#\r\n# This results in the error\r\n# AssertionError: [b'', b'Hello WorldGoodbye World']\r\ndecompressor = zlib.decompressobj(16 + zlib.MAX_WBITS)\r\nmessages = [decompressor.decompress(message1), decompressor.decompress(message2)]\r\nassert messages == [b\"Hello World\", b\"Goodbye World\"], messages\r\n```\r\n\r\n# Your environment\r\n\r\n\u003c!-- Include as many relevant details as possible about the environment you experienced the bug in --\u003e\r\n\r\n- CPython versions tested on: The bug is present in 3.12b2; the above script passes on 3.11 and earlier\r\n- Operating system and architecture: macOS and Linux\r\n\r\n\u003c!--\r\nYou can freely edit this text. Remove any lines you believe are unnecessary.\r\n--\u003e\r\n\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-105910\n* gh-105920\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/bdarnell","@type":"Person","name":"bdarnell"},"datePublished":"2023-06-15T01:20:58.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/105808/cpython/issues/105808"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e82fabd2-96ed-bf2a-f37f-637402bd85cb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 92B6:32EF48:DAC07D:12B819A:6969F255 |
| html-safe-nonce | af115da8aea55cbceda35c232662eb0024e72fd9ca5f60642169f625496d066a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MkI2OjMyRUY0ODpEQUMwN0Q6MTJCODE5QTo2OTY5RjI1NSIsInZpc2l0b3JfaWQiOiI0Nzc3NTYwNjM3ODc0NzYyMzI1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 61afa8417b44cc9176400a57f33bf4969321fc44b37aecb5e7c78a6288afc9bd |
| hovercard-subject-tag | issue:1757873059 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/105808/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0294fcaf6f25a8e9d2634f9afeb82ab29a1b8d668451159b6fd41f82359b400a/python/cpython/issues/105808 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0294fcaf6f25a8e9d2634f9afeb82ab29a1b8d668451159b6fd41f82359b400a/python/cpython/issues/105808 |
| og:image:alt | Bug report The change to add buffering to GzipFile.write (gh-89550, #101251) broke the GzipFile.flush method. The flush method previously called self.compress.flush, but now it only flushes the IO ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bdarnell |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7b32f1c7c4549428ee399213e8345494fc55b5637195d3fc5f493657579235e8 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | bdde15ad1b403e23b08bbd89b53fbe6bdf688cad |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width