Skip to content

Commit

Permalink
Merge pull request #12949 from Bo98/ghp-oom
Browse files Browse the repository at this point in the history
github_packages: fix OOM with large bottles
  • Loading branch information
Bo98 committed Mar 4, 2022
2 parents e12ce47 + ac9af0d commit 639be1b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Library/Homebrew/github_packages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

require "utils/curl"
require "json"
require "zlib"

# GitHub Packages client.
#
Expand All @@ -21,6 +22,9 @@ class GitHubPackages

URL_REGEX = %r{(?:#{Regexp.escape(URL_PREFIX)}|#{Regexp.escape(DOCKER_PREFIX)})([\w-]+)/([\w-]+)}.freeze

GZIP_BUFFER_SIZE = 64 * 1024
private_constant :GZIP_BUFFER_SIZE

# Translate Homebrew tab.arch to OCI platform.architecture
TAB_ARCH_TO_PLATFORM_ARCHITECTURE = {
"arm64" => "arm64",
Expand Down Expand Up @@ -338,11 +342,14 @@ def upload_bottle(user, token, skopeo, formula_full_name, bottle_hash, keep_old:
"os.version" => os_version,
}.reject { |_, v| v.blank? }

tar_sha256 = Digest::SHA256.hexdigest(
Utils.safe_popen_read("gunzip", "--stdout", "--decompress", local_file),
)
tar_sha256 = Digest::SHA256.new
Zlib::GzipReader.open(local_file) do |gz|
while (data = gz.read(GZIP_BUFFER_SIZE))
tar_sha256 << data
end
end

config_json_sha256, config_json_size = write_image_config(platform_hash, tar_sha256, blobs)
config_json_sha256, config_json_size = write_image_config(platform_hash, tar_sha256.hexdigest, blobs)

formulae_dir = tag_hash["formulae_brew_sh_path"]
documentation = "https://formulae.brew.sh/#{formulae_dir}/#{formula_name}" if formula_core_tap
Expand Down

0 comments on commit 639be1b

Please sign in to comment.