Hi,

The forthcoming PostgreSQL 7.1 will eliminate the previous 8KB limit
on attribute size.  Unfortunately, DBD-Pg 0.95 seems not to cope: when
storing large values via DBD-Pg perl dumps core.

I've seen the problem with perl 5.005_03 and perl 5.6.0, running on:

1. NetBSD-1.5/i386
2. NetBSD-1.4.2/i386
3. HP-UX 11i

with DBI-1.14, DBD-Pg 0.95, and PostgreSQL 7.1beta6.

As a sanity check I tested MySQL 3.23.36, DBI-1.14 and some version of
the mysql driver on NetBSD and saw no core dumps.

An example backtrace:

(gdb) bt
#0  0x481c18a7 in dbd_st_execute (sth=0x816b82c, imp_sth=0x8190704)
    at dbdimp.c:1104
#1  0x481bd2f5 in XS_DBD__Pg__st_execute (cv=0x81b32fc) at Pg.xs:460
#2  0x481aea17 in XS_DBI_dispatch ()
#3  0x80993fe in Perl_pp_entersub ()
#4  0x809467e in Perl_runops_standard ()
#5  0x805b310 in S_run_body ()
#6  0x805b069 in perl_run ()
#7  0x8058cf8 in main ()
#8  0x8058a49 in ___start ()
(gdb) p statement
$1 = 0x8237004 "INSERT INTO t VALUES ( '", '3' <repeats 176 times>...
(gdb) p dest
$2 = 0x8248000 <Address 0x8248000 out of bounds>
(gdb) l
1099                        if (*val == '\\' && !(isdigit(*(val+1)) && 
isdigit(*(val+2)) && isdigit(*(val+3))) ) {
1100                            *dest++ = '\\';
1101                        }
1102                    }
1103                    /* copy attribute to statement */
1104                    *dest++ = *val++;
1105                }
1106                /* quote string attribute */
1107                if(!SvNIOK(phs->sv) && SvOK(phs->sv) && phs->ftype > 1000) { /* 
avoid quoting NULL,  tpf: bind_param as numeric */
1108                    *dest++ = '\''; 

The following script will reproduce the problem: the code in this run
was trying to insert an 84229 byte attribute:

$ ./bug
1 13439
2 2176
3 84229
Memory fault (core dumped) 

$ cat bug
#! /usr/local/bin/perl -w

use strict;
use DBI;

use vars qw($dbh $sth $i $data $len);

$dbh = DBI->connect("dbi:Pg:", "", "",
                    { PrintError => 1, RaiseError => 1, AutoCommit => 1 });

$dbh->do("CREATE TEMPORARY TABLE t ( data text )");
$sth = $dbh->prepare("INSERT INTO t VALUES ( ? )");

for (1 .. 100) {
    $len = int(rand(100_000)) + 1;
    $data = ++$i x $len;
    warn "$i $len\n";
    $sth->execute($data);
}

$ perl -v

This is perl, v5.6.0 built for i386-netbsd

Copyright 1987-2000, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'.  If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.

$ perl -V
Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
  Platform:
    osname=netbsd, osvers=1.4Z, archname=i386-netbsd
    uname='netbsd nemeton.com.au 1.4z netbsd 1.4z (generic) #12: sat may 27 16:55:41 
pdt 2000 root@swinger:u1snapshotssrcsysarchi386compilegeneric i386 '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define 
    use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef
  Compiler:
    cc='cc', optimize='-O', gccversion=egcs-2.91.66 19990314 (egcs-1.1.2 release)
    cppflags='-fno-strict-aliasing'
    ccflags ='-fno-strict-aliasing'
    stdchar='char', d_stdstdio=undef, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    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, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =''
    libpth=/usr/lib
    libs=-lm -lc -lcrypt
    libc=/usr/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-R/lib '
    cccdlflags='-DPIC -fPIC ', lddlflags='--whole-archive -shared '


Characteristics of this binary (from libperl): 
  Compile-time options: USE_LARGE_FILES
  Built under netbsd
  Compiled at Jun 13 2000 05:49:45
  @INC:
    /usr/local/perl-5.6.0/lib/5.6.0/i386-netbsd
    /usr/local/perl-5.6.0/lib/5.6.0
    /usr/local/perl-5.6.0/lib/site_perl/5.6.0/i386-netbsd
    /usr/local/perl-5.6.0/lib/site_perl/5.6.0
    /usr/local/perl-5.6.0/lib/site_perl
    .

Regards,

Giles

Reply via email to