From b7a43604331fb8a7c8ba2b42d1caccb1d3eb97f9 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Tue, 26 Apr 2022 15:12:38 -0400 Subject: [PATCH] #parse_curl_output: increase default max_iterations The `max_iterations` value in `#parse_curl_output` is only intended to prevent its `while` loop from potentially turning into an endless loop. This should only come into play in exceptional circumstances but the current default value (5) is low enough that we're seeing it under normal circumstances. `#parse_curl_output` isn't intended to restrict the number of redirections (this should be done using the `--max-redirs` option in `curl) but it's effectively doing this in rare cases due to the low `max_iterations` default. This is a problem because `curl` can successfully return a response only to have `#parse_curl_output` error in relation to `max_iterations`. Originally the code in `#parse_curl_output` was used in the context of livecheck, where it's not a huge issue if a check fails. However, now the `#parse_curl_output` method is used in important parts of brew like `#curl_download`. We've received a report of a download failing with the "Too many redirects (max = 5)` error, effectively preventing the user from installing a formula [from a third-party tap]. Until we can come up with a more adaptive way of bounding this `while` loop, I think we should simply raise the default to something that's less likely to be encountered under normal circumstances (e.g., 25). --- Library/Homebrew/utils/curl.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index c385d02284..d182397618 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -400,7 +400,7 @@ module Utils # @return [Hash] A hash containing an array of response hashes and the body # content, if found. sig { params(output: String, max_iterations: Integer).returns(T::Hash[Symbol, T.untyped]) } - def parse_curl_output(output, max_iterations: 5) + def parse_curl_output(output, max_iterations: 25) responses = [] iterations = 0