Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bogus read after seek beyond end of string based file #10783

Closed
p5pRT opened this issue Oct 30, 2010 · 3 comments
Closed

Bogus read after seek beyond end of string based file #10783

p5pRT opened this issue Oct 30, 2010 · 3 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 30, 2010

Migrated from rt.perl.org#78716 (status was 'resolved')

Searchable as RT78716$

@p5pRT
Copy link
Author

p5pRT commented Oct 30, 2010

From peter.jaquiery@ihug.co.nz

Created by peter.jaquiery@ihug.co.nz

A read on a string based file handle incorrectly succeeds following a seek
beyond
the end of the string. The following code demonstrates the issue​:

-------- 8< -----------

#!/home/vmware/perl/perl
use strict;
use warnings;

my $str = '1234567890';

print "String file test\n";
open my $strIn, '<', \$str;
test ($strIn);
close $strIn;

open my $outFile, '>', 'temp.txt';
print $outFile $str;
close $outFile;

print "Disk file test\n";
open my $fileIn, '<', 'temp.txt';
test ($fileIn);
close $fileIn;

unlink 'temp.txt';

sub test {
  my ($fh) = @​_;
  seek $fh, 5, 1;
  my $ok = read $fh, my $buffer, 5;
  printf "Ok​: %d, \$buffer​: >%s<, eof​: %d, tell​: %d\n", $ok, $buffer,
  eof ($fh), tell ($fh);

  seek $fh, 5, 1;
  $ok = read $fh, $buffer, 5;
  printf "Ok​: %d, \$buffer​: >%s<, eof​: %d, tell​: %d\n", $ok, $buffer,
  eof ($fh), tell ($fh);
}

-------- 8< -----------

For an Active State build of 5.10.1 the code prints​:

String file test
Ok​: 5, $buffer​: >67890<, eof​: 1, tell​: 10
Ok​: 0, $buffer​: ><, eof​: 1, tell​: 15
Disk file test
Ok​: 5, $buffer​: >67890<, eof​: 1, tell​: 10
Ok​: 0, $buffer​: ><, eof​: 1, tell​: 15

For the test 5.12.2 exhibiting the problem the code prints​:

String file test
Ok​: 5, $buffer​: >67890<, eof​: 1, tell​: 10
Ok​: 5, $buffer​: > ><, eof​: 0, tell​: 20
Disk file test
Ok​: 5, $buffer​: >67890<, eof​: 1, tell​: 10
Ok​: 0, $buffer​: ><, eof​: 1, tell​: 15

Note that in the 5.12.2 case the string file test reports 5 bytes read after
the seek and eof is false. 5.10.0 reports 0 bytes read and eof true as
expected.

Perl Info

Flags:
    category=core
    severity=high

Site configuration information for perl 5.12.2:

Configured by vmware at Fri Oct 29 17:03:59 PDT 2010.

Summary of my perl5 (revision 5 version 12 subversion 2) configuration:

  Platform:
    osname=linux, osvers=2.6.15-27-386, archname=i686-linux
    uname='linux grandma-lamp 2.6.15-27-386 #1 preempt fri dec 8 17:51:56 
utc 2006 i686 gnulinux '
    config_args='-Dprefix=/home/wmware/perlroot/perl -des'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags 
='-fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion='', gccversion='4.0.3 (Ubuntu 4.0.3-1ubuntu5)', 
gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', 
lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.3.6.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.3.6'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib'

Locally applied patches:



@INC for perl 5.12.2:
    /home/wmware/perlroot/perl/lib/site_perl/5.12.2/i686-linux
    /home/wmware/perlroot/perl/lib/site_perl/5.12.2
    /home/wmware/perlroot/perl/lib/5.12.2/i686-linux
    /home/wmware/perlroot/perl/lib/5.12.2
    .


Environment for perl 5.12.2:
    HOME=/home/vmware
    LANG=en_US.UTF-8
    LANGUAGE=en
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games
    PERL_BADLANG (unset)
    SHELL=/bin/bash



@p5pRT
Copy link
Author

p5pRT commented Nov 27, 2010

From @cpansprout

Fixed by ab9f158.

@p5pRT
Copy link
Author

p5pRT commented Nov 27, 2010

@cpansprout - Status changed from 'new' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant