Skip Menu |

This queue is for tickets about the CHI CPAN distribution.

Report information
The Basics
Id: 98819
Status: new
Priority: 0/
Queue: CHI

Owner: Nobody in particular
Requestors: KENTNL [...]

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

Subject: CHI Digests can exceed max_key_length

CHI presently only interprets max_key_length to be a threshold at which digest is called.

However, its plausible that a digester may emit a key digest in excess of max_key_length.

Attached is some example code simulating this effect.

<< Keys exceeding the maximum length for the underlying driver are digested - see "max_key_length" and "key_digester" >>

Also, I notice that "max_key_length" is merely an attribute, and its implementation is such that if the user specifies any value, it will be taken in preference to the driver's default. However, this allows users to accidentally exceed drivers absolute maximums, and the drivers may not be even capable of this

^ And this explains why I've presently handled this with an around =>.  I could have probably done 'has +' on the attribute and changed its isa or something.

text/x-perl 829b
#!/usr/bin/env perl # ABSTRACT: Test keys longer than maxlength use strict; use warnings; use utf8; { package CHI::Driver::KeyLength; use Moo; extends 'CHI::Driver::Memory'; sub _real_max { return 64; } around max_key_length => sub { my ( $orig, $self, @args ) = @_; my $rval = $self->$orig(@args); my $real_max = $self->_real_max; return $rval > $real_max ? $real_max : $rval; }; around store => sub { my ( $orig, $self, $key, $data ) = @_; if ( ( length $key ) > $self->_real_max ) { die "Key too large\n"; } return $self->$orig($key,$data); }; } use CHI; my $ds = {}; my $d = CHI->new( driver => 'KeyLength' , datastore => $ds , on_set_error => 'warn', key_digester => 'Whirlpool' ); my $key = "hello" x 50; $d->set($key, "value"); print $d->get( $key );

"I could have probably done 'has +' on the attribute and changed its isa or something."


Actually, I couldn't have, because I have to determine what the databases maximum size is *after* instantiating it, and that would have introduced a real coding nightmare for 'isa => '

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

Please report any issues with to