Subject: | Truncated PGN can permanently wedge the entire module |
Date: | Thu, 21 Jan 2016 00:17:42 +0100 |
To: | bug-Chess-PGN-Parse [...] rt.cpan.org |
From: | "Steinar H. Gunderson" <sgunderson [...] bigfoot.com> |
Hi,
I noticed a problem with Chess::PGN::Parse in production; it turns out that
if you ever give it a truncated PGN, the entire module can go into a state
where it can no longer parse anything. This holds even if you create a new
object, since %memory is local to the module, not the object.
Example program to reproduce:
===
#! /usr/bin/perl
use strict;
use warnings;
use Chess::PGN::Parse;
my $pgn;
$pgn = Chess::PGN::Parse->new(undef, "[");
$pgn->read_game();
# At this point, the entire module is hosed. Try to e.g. parse a valid game:
my $text = <<"EOF";
[Event "78th Tata Steel GpA"]
[Site "Wijk aan Zee NED"]
[Date "2016.01.16"]
[White "Navara, David"]
[Black "Carlsen, Magnus"]
[Result "*"]
1. e4 *
EOF
$pgn = Chess::PGN::Parse->new(undef, $text);
if ($pgn->read_game()) {
print "Success\n";
} else {
print "Failure\n";
}
===
The same bug seems to make it impossible to have two different PGN objects
being read at the same time (e.g. if you want to diff two PGN files).
I've attached a patch, with test.
/* Steinar */
--
Homepage: https://www.sesse.net/
Message body is not shown because sender requested not to inline it.