From 1258992bdff8818d3ce868e98ccc3496069d996d Mon Sep 17 00:00:00 2001 From: Giovanni Tirloni Date: Tue, 27 Jan 2026 15:04:30 -0300 Subject: [ruby/rubygems] Fix gzip cache corruption when recovering from HTTP 416 responses When a Range request returns 416 (Range Not Satisfiable), the recovery path manually added an "Accept-Encoding: gzip" header before retrying. This bypasses Ruby's automatic gzip decompression mechanism. Ruby's Net::HTTP only sets decode_content=true (enabling automatic decompression) when Accept-Encoding is NOT present in the request headers. By manually setting this header, the decode_content flag remained false, causing gzip-compressed response bodies to be written directly to the compact index cache without decompression. This resulted in "ArgumentError: invalid byte sequence in UTF-8" errors when the corrupted cache was later read and parsed as text. The fix removes the explicit Accept-Encoding header, allowing Ruby's Net::HTTP to handle gzip compression transparently (as it does for all other requests). Ruby will still add Accept-Encoding: gzip automatically AND properly set decode_content=true for automatic decompression. Fixes https://github.com/ruby/rubygems/pull/9271 https://github.com/ruby/rubygems/commit/b48b090e38 --- lib/bundler/fetcher/downloader.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/bundler/fetcher/downloader.rb b/lib/bundler/fetcher/downloader.rb index 2eac6e7975..179eed8340 100644 --- a/lib/bundler/fetcher/downloader.rb +++ b/lib/bundler/fetcher/downloader.rb @@ -54,7 +54,6 @@ module Bundler when Gem::Net::HTTPRequestedRangeNotSatisfiable new_headers = headers.dup new_headers.delete("Range") - new_headers["Accept-Encoding"] = "gzip" fetch(uri, new_headers) when Gem::Net::HTTPRequestEntityTooLarge raise FallbackError, response.body -- cgit v1.2.3