Skip Menu |

This queue is for tickets about the DBD-PgPP CPAN distribution.

Report information
The Basics
Id: 31260
Status: resolved
Priority: 0/
Queue: DBD-PgPP

People
Owner: Nobody in particular
Requestors: crew@cs.stanford.edu (no email address)
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.05
Fixed in: 0.06



Subject: value corruption/sync lossage in _get_byte
if a field value is too long (I start noticing the problem consistently at around 4000 characters), DBD::PgPP::(ReadOnly)PacketStream::_get_byte() can neglect to read all of it, putting the stream out of sync, at which point we usually get an error of the form DBD::PgPP::db (whatever) failed: Unknown message type: '' at .../DBD/PgPP.pm line 981 The problem is that $stream->_if_short_then_add_buffer($length), as currently written is not actually guaranteed to return with $length characters in the buffer. _get_c_string allows for this but _get_byte does not and it should. I have supplied a patch. (I run perl v5.8.8 built for MSWin32-x86-multi-thread, ActiveState build 817 on Windows2000 SP4, mostly likely none of which matters)
Subject: x.txt
--- d:/hack/pl/lib/DBD/PgPP.pm.~4~ Sun Aug 13 18:32:34 2006 +++ Standard Input Wed Dec 05 23:24:16 2007 @@ -1267,7 +1267,10 @@ my $length = shift; $length = 1 unless defined $length; - $self->_if_short_then_add_buffer($length); + do { + $self->_if_short_then_add_buffer($length); + } until length($self->{buffer}) >= $length; + my $result = substr $self->{buffer}, 0, $length; $self->{buffer} = substr $self->{buffer}, $length; return $result; @@ -1375,7 +1378,10 @@ my $length = shift; $length = 1 unless defined $length; - $self->_if_short_then_add_buffer($length); + do { + $self->_if_short_then_add_buffer($length); + } until (length($self->{buffer}) - $self->{position}) >= $length; + my $result = substr $self->{buffer}, $self->{position}, $length; $self->{position} += $length; return $result; @@ -1395,7 +1401,7 @@ my $self = shift; $self->_if_short_then_add_buffer(2); my $result = unpack 'n', substr $self->{buffer}, $self->{position}, 2; - $self->{buffer} += 2; + $self->{position} += 2; return $result; }
This issue is believed to be fixed in DBD::PgPP 0.06. Please reopen this ticket if you can still reproduce the problem in that version. Thanks for the patch. I ended up reworking (and simplifying) a lot of the buffer-management code, so I'm not sure that any of your code still remains). But the analysis was very helpful. Apologies for the absurdly long delay. -- Aaron Crane