Skip Menu |

This queue is for tickets about the Device-Gsm CPAN distribution.

Report information
The Basics
Id: 58869
Status: resolved
Worked: 30 min
Priority: 0/
Queue: Device-Gsm

People
Owner: cosimo [...] cpan.org
Requestors: ccnweb [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: Incorrect decoding of text7
Hello Cosimo, I've found a bug in Device::Gsm::Pdu ( $Id: Pdu.pm 246 2009-08-18 19:16:55Z cosimo_2 $ ) This is a part of Device::Gsm v1.54 The example below prints 'Not match!' The bug is in decode_text7 procedure. It does not take in account the length value of encoded text and this leads to extra "\0" in the end of decoded text in some cases. #!/usr/bin/perl -l -- use strict; use warnings; use Device::Gsm::Pdu; my $text = '1234567'; if ( $text eq Device::Gsm::Pdu::decode_text7(Device::Gsm::Pdu::encode_text7( $text ))) { print 'Match'; } else { print 'Not match!'; }; __END__ The patch is vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv *** Pdu.pm 2010-06-27 18:42:33.268194936 +0300 --- Pdu.pm.fix 2010-06-27 18:43:11.028184539 +0300 *************** *** 93,99 **** $bits = substr $bits, 7; } ! $decoded; } # decode 8-bit encoded text --- 93,99 ---- $bits = substr $bits, 7; } ! substr $decoded, 0, $len; } # decode 8-bit encoded text ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ As for me, I d like to see more perlish code for the module e.g. sub encode_text7 { uc join '', map { unpack 'H2' } chr length $_[0], map { pack 'b8', $_ } unpack '(A8)*', join '', unpack '(b7)*', $_[0]; } sub decode_text7 { substr join('', map { pack 'b7', $_} unpack '(A7)*', join '', map { unpack '(b8)*', pack 'H2', $_ } unpack '(A2)*', substr $_[0], 2), 0, hex substr $_[0], 0, 2; } -- Sincerely yours, Alexander Onokhov
Thanks Alexander. Your fix has been applied with a new test case. I just released v1.55 out on CPAN. Also thanks for the new code you proposed. Looks better, I'll apply later.
Subject: Re: [rt.cpan.org #58869] Incorrect decoding of text7
Date: Mon, 28 Jun 2010 13:01:19 +0300
To: bug-Device-Gsm [...] rt.cpan.org
From: Alexander Onokhov <ccnweb [...] gmail.com>
Here is more straight variant of encode sub encode_text7 { uc unpack 'H*', pack 'C b*', length $_[0], join '', unpack '(b7)*', $_[0]; } -- Alexander
Subject: Re: [rt.cpan.org #58869] Incorrect decoding of text7
Date: Mon, 28 Jun 2010 13:34:11 +0300
To: bug-Device-Gsm [...] rt.cpan.org
From: Alexander Onokhov <ccnweb [...] gmail.com>
These are procedures tuned up by mtve sub decode_text7 { pack '(b*)*', unpack 'C/(a7)', pack 'C a*', unpack 'C b*', pack 'H*', $_[0] } sub encode_text7 { uc unpack 'H*', pack 'C b*', length $_[0], join '', unpack '(b7)*', $_[0]; } -- Alexander
The updated code is released on CPAN.