{"record":{"id":"2dbc746bbd1c7b8f","repo":"ruby/rubygems","slug":"expected-count-elements-but-only-remaining","errorCode":null,"errorMessage":"expected #{count} elements, but only #{remaining} bytes remain","messagePattern":"expected #(.+?) elements, but only #(.+?) bytes remain","errorType":"exception","errorClass":"Gem::SafeMarshal::Reader::LengthTooLongError","httpStatus":null,"severity":"error","filePath":"lib/rubygems/safe_marshal/reader.rb","lineNumber":107,"sourceCode":"        else\n          signed = (b ^ 128) - 128\n          if b >= 128\n            signed + 5\n          else\n            signed - 5\n          end\n        end\n      end\n\n      # Reads an element count and validates it against the number of bytes\n      # remaining in the input, since each element to be read consumes at\n      # least one byte. This prevents allocating huge backing stores for\n      # maliciously crafted lengths that could never be satisfied.\n      def read_count\n        count = read_integer\n        raise NegativeLengthError if count < 0\n        remaining = @io.size - @io.pos\n        raise LengthTooLongError, \"expected #{count} elements, but only #{remaining} bytes remain\" if count > remaining\n        count\n      end\n\n      def read_element\n        type = read_byte\n        case type\n        when 34 then read_string # ?\"\n        when 48 then read_nil # ?0\n        when 58 then read_symbol # ?:\n        when 59 then read_symbol_link # ?;\n        when 64 then read_object_link # ?@\n        when 70 then read_false # ?F\n        when 73 then read_object_with_ivars # ?I\n        when 84 then read_true # ?T\n        when 85 then read_user_marshal # ?U\n        when 91 then read_array # ?[\n        when 102 then read_float # ?f\n        when 105 then Elements::Integer.new(read_integer) # ?i","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/ruby/rubygems/blob/86cbb817a38ce8477b181c17467a703ded3f2be8/lib/rubygems/safe_marshal/reader.rb#L89-L125","documentation":"Error \"expected #{count} elements, but only #{remaining} bytes remain\" thrown in ruby/rubygems.","triggerScenarios":"Thrown at lib/rubygems/safe_marshal/reader.rb:107 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["The marshal data is truncated mid-structure; re-download the gem or metadata file"],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"86cbb817a38ce8477b181c17467a703ded3f2be8","analyzedAt":"2026-08-23T06:27:48.159Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}