{"record":{"id":"d05d3a4cb5b49cff","repo":"ruby/ruby","slug":"wrong-requirements","errorCode":null,"errorMessage":"wrong @requirements","messagePattern":"wrong @requirements","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/rubygems/requirement.rb","lineNumber":214,"sourceCode":"    requirements.map {|r| r.first == \"~>\" ? [r[0], r[1].to_s] : r }.sort.hash\n  end\n\n  def marshal_dump # :nodoc:\n    [@requirements]\n  end\n\n  def marshal_load(array) # :nodoc:\n    @requirements = array[0]\n\n    if Array === @requirements\n      return if @requirements.all? do |r|\n        next false unless r.size == 2\n        r[0] = \"=\" unless r.first.is_a?(String)\n        r.last.is_a?(Gem::Version)\n      end\n    end\n\n    raise TypeError, \"wrong @requirements\"\n  end\n\n  def yaml_initialize(tag, vals) # :nodoc:\n    vals.each do |ivar, val|\n      instance_variable_set \"@#{ivar}\", val\n    end\n  end\n\n  def init_with(coder) # :nodoc:\n    yaml_initialize coder.tag, coder.map\n  end\n\n  def encode_with(coder) # :nodoc:\n    coder.add \"requirements\", @requirements\n  end\n\n  ##\n  # A requirement is a prerelease if any of the versions inside of it","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/ruby/ruby/blob/0e5b888e1c355f3f728f2659f085820937dada48/lib/rubygems/requirement.rb#L196-L232","documentation":"When a Gem::Requirement is restored via Marshal (marshal_load validates that @requirements is an array whose elements are [op, Gem::Version] pairs; non-string ops are coerced to '='). A TypeError means the marshalled payload did not contain that shape - typically a corrupted or foreign marshal blob, e.g. a truncated specifications/*.gemspec cache file or data written by an incompatible layout.","triggerScenarios":"Marshal.load of a gem's marshalled specification where the requirements payload is corrupt (truncated file, disk/full-disk write, or data tampering); manually crafted Marshal streams fed into Gem::Requirement; loading spec caches copied between mismatched RubyGems installations.","commonSituations":"Interrupted `gem install` leaving a half-written .gemspec marshal file; disk-full or crash during cache updates; copying GEM_HOME/specifications between machines with different RubyGems versions; hand-editing marshal dumps.","solutions":["Reinstall the affected gem to regenerate its specification: `gem uninstall <gem> && gem install <gem>` or `gem pristine <gem>`","Delete the corrupt marshalled spec file (the path usually appears in the backtrace under specifications/) and rerun the install","For a broadly corrupted cache: `gem pristine --all` after ensuring a healthy disk and a single consistent RubyGems version per GEM_HOME","Never hand-edit Marshal dumps; regenerate them from the source .gem"],"exampleFix":"# before\n$ gem list -d  # => TypeError: wrong @requirements\n\n# after\n$ rm ~/.gem/specifications/broken_gem-1.0.gemspec\n$ gem install broken_gem -v 1.0","handlingStrategy":"try-catch","validationCode":"# sanity-check a marshal file before loading: marshal streams start with 0x04 0x08\nabort 'not a Marshal stream' unless File.binread(path, 2) == \"\\x04\\x08\"\n# and validate load results instead of trusting them","typeGuard":null,"tryCatchPattern":"begin\n  spec = Marshal.load(File.binread(spec_path))\nrescue TypeError, ArgumentError\n  warn \"corrupt spec cache #{spec_path} - regenerating\"\n  File.delete(spec_path)\n  retry_after_reinstall = true\nend","preventionTips":["Treat spec caches as disposable: `gem pristine --all` rebuilds them","Avoid interrupted installs (ctrl-C during `gem install`) and disk-full conditions that truncate marshal files","Never hand-edit Marshal dumps; regenerate from the source .gem","Keep one RubyGems version per GEM_HOME when copying installations around"],"tags":["rubygems","marshal","corruption","requirement","deserialization"],"backgroundTag":"corrupt-marshaled-data","analyzedSha":"0e5b888e1c355f3f728f2659f085820937dada48","analyzedAt":"2026-08-21T14:25:43.473Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}