Skip to content

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

Closed

Description

@p5pRT

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

Searchable as RT78716$

Activity

  1. p5pRT commented on Oct 30, 2010

    @p5pRT
    Author

    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
    
    
    
    
  2. p5pRT commented on Nov 27, 2010

    @p5pRT
    Author

    From @cpansprout

    Fixed by ab9f158.

  3. p5pRT commented on Nov 27, 2010

    @p5pRT
    Author

    @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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions