Question: how to deal with Regexp::Timeout in _decode_uri_component?
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 35/100
Piste de recherche
Commencez dans lib/uri/common.rb au niveau du chemin _decode_uri_component référencé et reproduisez le Regexp::TimeoutError avec une charge utile volumineuse encodée en pourcentage. Discutez et définissez avec les maintainers le comportement URI souhaité, puis ajoutez une couverture pour le cas de timeout et vérifiez que l’approche choisie gère l’entrée signalée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Hi folks, thanks for maintaining the URI gem!
I faced the following issue with a 65MB mime-body payload and over 13 million percent-encoded characters:
Regexp::TimeoutError POST /rails/action_mailbox/mailgun/inbound_emails/mime
vendor/bundle/ruby/3.3.0/gems/uri-0.13.3/lib/uri/common.rb:400:in `match?': regexp match timeout (Regexp::TimeoutError)
from vendor/bundle/ruby/3.3.0/gems/uri-0.13.3/lib/uri/common.rb:400:in `_decode_uri_component'
Ref:
- https://github.com/ruby/uri/blob/v0.13.3/lib/uri/common.rb#L400
- https://github.com/ruby/uri/blob/v1.1.1/lib/uri/common.rb#L464
My workaround was to monkey patch the decode_www_form_component to avoid the Regexp code path if it times out:
module URIFormComponentLinearDecode
ORIGINAL_DECODE_WWW_FORM_COMPONENT = URI.method(:decode_www_form_component)
DECODE_TABLE = URI.const_get(:TBLDECWWWCOMP_)
def decode_www_form_component(str, enc = Encoding::UTF_8)
ORIGINAL_DECODE_WWW_FORM_COMPONENT.call(str, enc)
rescue Regexp::TimeoutError
raise unless str.is_a?(String)
Rails.logger.info("[URIFormComponentLinearDecode] bytesize=#{str.bytesize}")
linear_decode_www_form_component(str, enc)
end
private
def linear_decode_www_form_component(str, enc)
source = str.b
output = String.new(capacity: source.bytesize).b
index = 0
while index < source.bytesize
byte = source.getbyte(index)
case byte
when 37 # "%"
raise ArgumentError, "invalid %-encoding (#{str})" unless index + 2 < source.bytesize
encoded = source.byteslice(index, 3)
decoded = DECODE_TABLE[encoded]
raise ArgumentError, "invalid %-encoding (#{str})" unless decoded
output << decoded
index += 3
when 43 # "+"
output << DECODE_TABLE["+"]
index += 1
else
output << byte
index += 1
end
end
output.force_encoding(enc)
end
end
URI.singleton_class.prepend(URIFormComponentLinearDecode)
I was wondering:
- Did you guys face this problem before?
- Do you have a better approach to it?
- Do you think a solution to this issue belongs in the URI codebase?
- Do you think it would make sense to use a native function in this case?
I'm happy to contribute with a PR if you would like me to. Please let me know if you have any thoughts.
Thanks.
- Langage dominant
- Ruby
- Étoiles
- 125
- Forks
- 68
- Merge moyen
- 4 h 45 min
- PR mergées (30 j)
- 1
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de ruby/uri
-
Difficulté 3/5 1-2 jours Accessibilité débutants 48/100
-
upstream contact for DebianOuverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 25/100
-
Difficulté 3/5 1-2 jours Accessibilité débutants 68/100
-
Difficulté 3/5 1-2 jours Accessibilité débutants 52/100
-
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
Issues similaires
-
documentation
Difficulté 1/5 Moins d'une heure Accessibilité débutants 86/100
bridgetownrb/bridgetown#1130 ·
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
stripe/stripe-ruby#1994 ·
Les mainteneurs répondent en général sous 1 jour
-
[Fehler]: /abdeckstift wirft 500 — part_type aus der Phonemreduction-Umbenennung nicht mitgezogenOuvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 73/100
wort-schule/wort.schule#787 ·
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
lugassawan/swe-workbench#799 ·
Les mainteneurs répondent en général sous 1 jour
-
2.8.6: NoMethodError "undefined method 'first'" in profdata_coverage_dir whenever --scheme is usedOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
SlatherOrg/slather#586 · 2 commentaires ·