CodeSampleX

Beispiel

csv 3.3.2: Show that CSV.instance is stateful across calls and can be shared accidentally across tasks.

Verifiziertes Beispiel für gem csv 3.3.2: Show that CSV.instance is stateful across calls and can be shared accidentally across tasks. Der Vertrag lief auf…

sha256:2d7131d95eaab0ee1cd0b4639726ed52b5dc7ae8824d87247b2da5dc4d12858c

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
2
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung ruby linux x64 ruby ruby rubygems

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
ruby 3 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · rubygems@1
2026-08-16
ruby 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · rubygems@1
2026-08-18

Fall

HOW
Ziel
Show that CSV.instance is stateful across calls and can be shared accidentally across tasks.
Pakete
Symbole
  • CSV.instance
Umgebung
ruby
Erstellt
2026-08-16T15:31:10Z

Contract

  1. CSV.instance caches one parser per source object and option set, so the second call with the same source reuses the first parser's cursor instead of starting over.
  2. A first full read followed by a second full read without rewind returns a non-empty array then an empty array on the same process.
  3. Two task-local references created with CSV.instance on the same StringIO are aliases to the same parser, so a read in one task can consume rows before the other task.

Dateien

  • Gemfile
  • NOTES.md
  • csx.json
  • test/contract.rb

Quellartefakt herunterladen (tar.gz)

Quelltext

Gemfile
source "https://rubygems.org"

gem "csv", "3.3.2"
NOTES.md
A prior public sample for this package covered converter/header parsing behavior (`sha256:25a66e52b7b289174635a51806d16ef38f17c9b1bb37d63fa67c4b218e537022`), so this sample avoids that solved trap and instead targets shared-parser state.
A naïve model expecting `CSV.instance` calls to be independent would pass only the first read and then silently pass an empty second read on Ruby 3.3.2.
csx.json
{"case":{"believed":"Calling CSV.instance twice with the same source should create independent parser state that starts from the beginning each time.","caseId":"case:sha256:bb6ec82203454c4c6b3dfeca2ef239902788197b3e4293838c1cfc28d5264139","contract":["CSV.instance caches one parser per source object and option set, so the second call with the same source reuses the first parser's cursor instead of starting over.","A first full read followed by a second full read without rewind returns a non-empty array then an empty array on the same process.","Two task-local references created with CSV.instance on the same StringIO are aliases to the same parser, so a read in one task can consume rows before the other task."],"goal":"Show that CSV.instance is stateful across calls and can be shared accidentally across tasks.","kind":"HOW","packages":["pkg:gem/csv@3.3.2"],"schemaVersion":1,"symbols":["CSV.instance"]},"contractCommand":["ruby","test/contract.rb"],"environment":{"arch":"x64","ecosystem":"gem","executionContext":"ruby","language":"ruby","os":"linux","packageManager":"rubygems","runtime":"ruby","schemaVersion":1},"license":"MIT-0","packages":["pkg:gem/csv@3.3.2"],"schemaVersion":1,"symbols":["CSV.instance"],"verifierAdapter":"rubygems@1"}
test/contract.rb
require "rubygems"
require "csv"
require "stringio"

def assert(label)
  raise "Assertion failed: #{label}" unless yield
end

# `CSV.instance` is memoized and reused for the same source object.
source = "1,2\n3,4\n"
first = CSV.instance(source).read
second = CSV.instance(source).read
assert("same parser state is reused on second call") do
  first == [["1", "2"], ["3", "4"]] && second == []
end

# Sharing one `StringIO` between task-local references points at the same parser.
stream = StringIO.new("1,2\n3,4\n5,6\n")
reader_a = CSV.instance(stream)
reader_b = CSV.instance(stream)
assert("shared instance is literally the same object") { reader_a.equal?(reader_b) }

first_row = reader_a.shift
second_row = reader_b.shift
third_row = reader_a.shift
assert("tasks share cursor state") do
  first_row == ["1", "2"] && second_row == ["3", "4"] && third_row == ["5", "6"]
end

Ursprungs-Seeder

csx-seed