Skip Menu |

This queue is for tickets about the JSON-SL CPAN distribution.

Report information
The Basics
Id: 100564
Status: resolved
Priority: 0/
Queue: JSON-SL

People
Owner: MNUNBERG [...] cpan.org
Requestors: tino.didriksen [...] gmail.com
Cc:
AdminCc:

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



Subject: Key is magically not itself
Testcase: http://ideone.com/9PoHhc or attachment. When working with JSON::SL objects/hashes, keys that compare equal to a string are not actually equal to that string when used as lookup. E.g., $key eq 'id' but using 'id' itself to access the value results in uninitialized read.
Subject: id_isnt_id.pl
#!/usr/bin/env perl # -*- mode: cperl; indent-tabs-mode: nil; tab-width: 3; cperl-indent-level: 3; -*- BEGIN { $|=1; } use strict; use warnings; use utf8; use Data::Dumper; use JSON::SL; my $p = JSON::SL->new; $p->utf8(1); $p->noqstr(1); $p->nopath(1); $p->set_jsonpointer(['/^']); my $buf = <<JSON; [{"id": "hello"}] JSON $p->feed($buf); while (my $obj = $p->fetch) { my %val = %{$obj->{Value}}; foreach my $k (sort keys %val) { # This prints: id => hello print "$k => $val{$k}\n"; # This prints: $VAR1 = 'id'; print Dumper($k); if ($k eq 'id') { # This triggers: Use of uninitialized value $val{"id"} # So, id != id ? print "id => $val{id}\n"; } } print "\n"; # Now for the fun bit: This causes 2 rows of key id $val{'id'} = 5; foreach my $k (sort keys %val) { print "$k => $val{$k}\n"; print Dumper($k); } } =pod id => hello $VAR1 = 'id'; Use of uninitialized value $val{"id"} in concatenation (.) or string at /home/tino/parsers/bin/json_sl.pl line 32. id => id => hello $VAR1 = 'id'; id => 5 $VAR1 = 'id'; =cut
It would seem that this does not happen if you do a full decode (those two go through more or less the same codepaths..) I am investigating this.. On Wed Nov 26 11:23:49 2014, https://www.google.com/accounts/o8/id?id=AItOawmVIxZvJRV891D4v94gdb3PG8qiqj4xy9M wrote: Show quoted text
> Testcase: http://ideone.com/9PoHhc or attachment. > > When working with JSON::SL objects/hashes, keys that compare equal to > a string are not actually equal to that string when used as lookup. > > E.g., $key eq 'id' but using 'id' itself to access the value results > in uninitialized read.
Ok, I've figured out what's happening and it's specific to $p->utf8(1); the problem isn't with utf8 per se, but rather with the optimized hash insertion code not setting the proper flags on the hashref itself when it's inserting the item. As a temporary workaround, you can either: 1) Disable UTF8 (NOTE: this does not do anything special except not apply the SvUTF flag to strings it encounters) 2) In SL.xs, temporarily patch line 500 (create_hk_THX) so that the 'state->nescapes' branch is always true. This will make the code slower because it will use a more published way to access Perl's hashes (which in this case unfortunately means copying the keys). Depending on your dataset, this might not be a big deal. On Sun Nov 30 11:56:22 2014, MNUNBERG wrote: Show quoted text
> It would seem that this does not happen if you do a full decode (those > two go through more or less the same codepaths..) I am investigating > this.. > > On Wed Nov 26 11:23:49 2014, > https://www.google.com/accounts/o8/id?id=AItOawmVIxZvJRV891D4v94gdb3PG8qiqj4xy9M > wrote:
> > Testcase: http://ideone.com/9PoHhc or attachment. > > > > When working with JSON::SL objects/hashes, keys that compare equal to > > a string are not actually equal to that string when used as lookup. > > > > E.g., $key eq 'id' but using 'id' itself to access the value results > > in uninitialized read.
See if this works for you: https://github.com/mnunberg/perl-JSON-SL/tree/utf8_fix On Wed Nov 26 11:23:49 2014, https://www.google.com/accounts/o8/id?id=AItOawmVIxZvJRV891D4v94gdb3PG8qiqj4xy9M wrote: Show quoted text
> Testcase: http://ideone.com/9PoHhc or attachment. > > When working with JSON::SL objects/hashes, keys that compare equal to > a string are not actually equal to that string when used as lookup. > > E.g., $key eq 'id' but using 'id' itself to access the value results > in uninitialized read.
Resolved in upcoming 1.0.3 which should be available in just a few minutes