[IO::Handle] Destroying a borrowed DATA handle closes the stream

Aperta
#2,039 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
java
Ambito
backend

Direzione di ricerca

Start by reading IO::Handle::DESTROY and the overlapping RuntimeIO ownership work in #1649 and PR #1938; coordinate before changing handle cleanup. Add the focused regression for destroying a wrapper around a borrowed package DATA handle, first validating it with system Perl. Done means the borrowed handle remains readable, owned descriptors and explicit close still clean up, and the regression plus CPAN::Repository 0.010 suite pass on both backends.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area:io area:runtime blocked:ownership bug

Summary

PerlOnJava closes a package's borrowed DATA handle when a temporary FileHandle wrapper is destroyed. File::MMagic uses this pattern for its built-in magic table. After the first archive type check, the package DATA stream is closed; subsequent checks load no magic entries and return application/octet-stream. Archive::Any has no handler for that type, so Dist::Data then calls extract on an undefined archive object.

This caused CPAN::Repository 0.010 to fail in CPAN random run 20261111-090841-71684, test t/10-simple.t.

Reproducer

With File::MMagic 1.30 and two gzip archives, run both checks in the same process:

use File::MMagic;

for my $path (@ARGV) {
    print File::MMagic->new()->checktype_filename($path), "\n";
}

Use the CPAN::Repository 0.010 fixtures My-Sample-Distribution-0.003.tar.gz and My-Other-Sample-0.001.tar.gz as the two arguments.

Expected on system Perl:

application/x-gzip
application/x-gzip

Actual on PerlOnJava JVM and interpreter:

application/x-gzip
application/octet-stream

The archived t/10-simple.t failure then reports:

No handler available for type 'application/octet-stream'
Can't call method "extract" on an undefined value

Root cause evidence

File::MMagic::new borrows *File::MMagic::DATA{IO} and blesses that handle as a FileHandle. PerlOnJava's IO::Handle::DESTROY unconditionally closes a handle with a defined fileno, without distinguishing a borrowed package handle from a handle owned by that wrapper. Instrumentation shows that after the temporary detector is released, the DATA handle is closed (tell returns -1 and eof is true); the next detector loads no magic entries. Keeping a detector object alive across both calls avoids the failure.

Validation and environment

  • CPAN::Repository 0.010: PerlOnJava JVM and interpreter both fail t/10-simple.t with this error.
  • System Perl 5.34.1: all four upstream test files pass, 16 tests total. File::MMagic 1.30 and MIME::Types 2.30 were installed in an isolated temporary library because the host Perl lacked them.
  • PerlOnJava source: 308a379fc6778e5db851d10c260656e82ce03944; OpenJDK 24.0.2, macOS 26.7.1 arm64.
  • The target distribution and the relevant archive dependencies are pure Perl; this is not an XS build or environment-prerequisite failure.

Acceptance criteria

  • Add a focused project-owned regression showing that destroying a wrapper for a borrowed package DATA handle leaves that handle readable, validated first with system Perl.
  • Preserve cleanup for genuinely owned file descriptors and explicit close behavior.
  • Pass the focused regression on JVM and interpreter, and pass the CPAN::Repository 0.010 upstream suite on both backends.

Coordination and related issues

The active #1649 ownership work and PR #1938 cover broad IO resource ownership and modify RuntimeIO; coordinate before editing overlapping handle cleanup paths. #1244 records a different compile-time-loading failure that also affected a DATA handle. #2024/#2035 addressed ambiguous close warnings, not this ownership bug.

Lingua principale
Perl
Stelle
67
Fork
8
Merge medio
5h 12m
PR unite (30g)
131

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di fglock/PerlOnJava

Tutte le issue di fglock/PerlOnJava

Issue simili

Altre issue su Perl

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.