Hacker News new | past | comments | ask | show | jobs | submit

  str = ("\x82\xA0" + ("A" * (2**32 + 4))).force_encoding(Encoding::Shift_JIS)
  
  puts "str.bytesize: #{str.bytesize}"
  puts "str.encoding: #{str.encoding}"
  puts "str.valid_encoding?: #{str.valid_encoding?}"
  
  new_str = str.downcase
  
  puts "new_str.bytesize: #{new_str.bytesize}"
  puts "new_str.bytes:    #{new_str.bytes}"
  puts "new_str.encoding: #{new_str.encoding}"
outputs on an unfixed version:

  str.bytesize: 4294967302
  str.encoding: Shift_JIS
  str.valid_encoding?: true
  new_str.bytesize: 6
  new_str.bytes:    [130, 160, 97, 97, 97, 97]
  new_str.encoding: Shift_JIS
also I'd suggest you check out CVE-2026-128084 (GHSA-4fqr-96q8-xrfx) if you are interested in C bugs impacting Ruby on Rails
I'm worried that this can be used against a standard rails app somehow, as I'm sure there's regex parsing and downcasing somewhere in the stack.

However, if you need to do an operation on a malicious multi gb string to trigger this, it makes me slightly less concerned that regular rails apps are vulnerable.

But I'm no a security expert, is my assumption just wishful thinking?

Rails accepts multi gb strings fine, as long as you have enough memory/swap (even with rack trying to prevent this). Having nginx in front isn't guaranteed to protect you either, see CVE-2026-95101 in nginx for an example.
{"deleted":true,"id":50558448,"parent":50557395,"time":1795085198,"type":"comment"}