Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.96k stars 555 forks source link

hash collision? #9522

Closed p5pRT closed 16 years ago

p5pRT commented 16 years ago

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

Searchable as RT59796$

p5pRT commented 16 years ago

From spencerdmyers@gmail.com

I have attached the bug report file and a perl file that uses a perl5.10 interpreter. There are some print statements in the perl file. On my system the print statements will change after a different key to the hash has been assigned. The first print statement will print correctly and the second will

print "unknown" which is the value to the hash right before the second print statement. Please let me know if you get the same behavior and/or how to fix this problem.

Thanks\,

p5pRT commented 16 years ago

From spencerdmyers@gmail.com

Created by andrew_lowe@amis.com

I built a database with hashes of hashes. The value of one of the hash chains is getting changed by a different hash chain. I can put a print statement before and after it and can see that it is changing. The keys are different\, but for some reason they are changing the value from the other key set. If I change one of the keys by a single character\, then I don't see this phenomenon.

Perl Info ``` Flags: category=core severity=critical Site configuration information for perl v5.8.7: Configured by sserr at Fri Aug 15 12:11:12 MDT 2008. Summary of my perl5 (revision 5 version 8 subversion 7) configuration: Platform: osname=linux, osvers=2.6.9-67.0.4.elsmp, archname=i686-linux uname='linux borg005 2.6.9-67.0.4.elsmp #1 smp fri jan 18 05:00:58 est 2008 i686 i686 i386 gnulinux ' config_args='-de -Dprefix=/home/apps/cadapps/20080815' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef 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 -I/usr/include/gdbm', optimize='-O2', cppflags='-fno-strict-aliasing -pipe -I/usr/local/include -I/usr/include/gdbm' ccversion='', gccversion='3.4.6 20060404 (Red Hat 3.4.6-9)', 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 -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc libc=/lib/libc-2.3.4.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.3.4' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib' Locally applied patches: @INC for perl v5.8.7: /home/apps/cadapps/20080815/lib/perl5/5.8.7/i686-linux /home/apps/cadapps/20080815/lib/perl5/5.8.7 /home/apps/cadapps/20080815/lib/perl5/site_perl/5.8.7/i686-linux /home/apps/cadapps/20080815/lib/perl5/site_perl/5.8.7 /home/apps/cadapps/20080815/lib/perl5/site_perl/5.10.0 /home/apps/cadapps/20080815/lib/perl5/site_perl . Environment for perl v5.8.7: HOME=/home/lowea LANG=C LANGUAGE (unset) LD_LIBRARY_PATH=/cad/amis/tools/etc/current/rhel4.0/lib:/home/apps/ldv/linux/ius58usr1/tools/lib:/cad/synopsys/linux/dcm LOGDIR (unset) PATH=.:/cad/amis/bin.linux:/cad/amis/tools/ADS/bin:/cad/amis/tools/ADS/current/software:/cad/amis/tools/etc/current/rhel4.0/bin:/cad/amis/tools/ADS/current/system/bin:/home/apps/access/current/x86-linux:/home/apps/access/gui/linux:/cad/cadapps/bin:.:/usr/local/bin:/cad/scripts:/cad/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/lib/java/bin:/usr/games/bin:/usr/games:/opt/gnome/bin:/opt/kde2/bin:/opt/kde/bin:/opt/gnome/bin/sbin:/usr/X11/bin:/usr/openwin/bin:/cad/scripts:/cad/primetime/linux/syn/bin:/home/apps/dapsdata/Daps7/exe/linux:/home/apps/ldv/linux/ius58usr1/tools/dfII/bin:/home/apps/ldv/linux/ius58usr1/tools/bin:/home/apps/ldv/linux/ius58usr1/tools/vtools/vfault/bin:/cad/msd/tools/bin:/cad/msd/tools/dfII/bin:/cad/synopsys/linux/syn/bin:/cad/usim/tools/bin:/cad/verplex/bin PERL_BADLANG (unset) SHELL=/bin/csh ```
p5pRT commented 16 years ago

From spencerdmyers@gmail.com

perl_bug.pl.gz

p5pRT commented 16 years ago

From @rgs

2008/10/11 via RT Spencer Myers \perlbug\-followup@​perl\.org​:

I have attached the bug report file and a perl file that uses a perl5.10 interpreter. There are some print statements in the perl file. On my system the print statements will change after a different key to the hash has been assigned. The first print statement will print correctly and the second will

print "unknown" which is the value to the hash right before the second print statement. Please let me know if you get the same behavior and/or how to fix this problem.

I'll extract two lines from your script :

$hash{'amis150hx'}{'amis150hxadgx'}{'highest_drive_inv'} = "none"; $hash{'amis150hx'}{'amis150hxadgx'}{'highest_drive_inv'}{'highest_drive_inv_pin_list'} = "unknown";

Here you're assigning to a hash named %none (because your script doesn't use "strict"). There are other instances of this same bug. That's the origin of your bug​: you're using the same hash several times\, via different aliases.

p5pRT commented 16 years ago

The RT System itself - Status changed from 'new' to 'open'

p5pRT commented 16 years ago

@rgs - Status changed from 'open' to 'resolved'

p5pRT commented 16 years ago

From @schwern

Spencer Myers (via RT) wrote​:

# New Ticket Created by "Spencer Myers" # Please include the string​: [perl #59796] # in the subject line of all future correspondence about this issue. # \<URL​: http​://rt.perl.org/rt3/Ticket/Display.html?id=59796 >

I have attached the bug report file and a perl file that uses a perl5.10 interpreter. There are some print statements in the perl file. On my system the print statements will change after a different key to the hash has been assigned. The first print statement will print correctly and the second will

print "unknown" which is the value to the hash right before the second print statement. Please let me know if you get the same behavior and/or how to fix this problem.

Thanks for your report. This is not a bug in Perl but a subtle bug in your code. The code is accidentally using a "symbolic reference" which lets one refer to a variable by name.

$hash{'amis350ua'}{'amis350uaascb'}{'highest_drive_inv'} is the string 'inv48_b' (assigned on line 3348). That makes $hash{'amis350ua'}{'amis350uaascb'}{'highest_drive_inv'}{highest_drive_inv_pin_list} equivalent to this​:

$inv48_b{highest_drive_inv_pin_list};

$hash{'amis350ua'}{'amis350uaascb'}{'highest_drive_inv'} is also the string 'inv48_b' (assigned on line 4149) so it also refers to %inv48_b.

Symbolic references are dangerous and hard to debug. To avoid them\, use strict.

#!/cad/cadapps/bin/perl5.10.0 -w

use strict; my %hash;

$hash{'amis150hx'}{'amis150hxadgx'}{'status'} = "skip"; $hash{'amis150hx'}{'amis150hxadgx'}{'netlist_path'} = "unknown"; ...

And it will error if you try to use a symbolic ref.

Can't use string ("none") as a HASH ref while "strict refs" in use at /Users/schwern/Downloads/perl_bug.pl line 43.

-- 39. Not allowed to ask for the day off due to religious purposes\, on the   basis that the world is going to end\, more than once.   -- The 213 Things Skippy Is No Longer Allowed To Do In The U.S. Army   http​://skippyslist.com/list/