develooper Front page | perl.perl5.porters | Postings from October 2010

[perl #78716] Bogus read after seek beyond end of string based file

From:
Peter Jaquiery
Date:
October 29, 2010 21:51
Subject:
[perl #78716] Bogus read after seek beyond end of string based file
Message ID:
rt-3.6.HEAD-7154-1288407507-458.78716-75-0@perl.org
# New Ticket Created by  "Peter Jaquiery" 
# Please include the string:  [perl #78716]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=78716 >



This is a bug report for perl from peter.jaquiery@ihug.co.nz,
generated with the help of perlbug 1.39 running under perl 5.12.2.


-----------------------------------------------------------------
[Please describe your issue here]

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.


[Please do not change anything below this line]
-----------------------------------------------------------------
---
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





nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About