ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CBOR-XS/XS.pm
(Generate patch)

Comparing CBOR-XS/XS.pm (file contents):
Revision 1.60 by root, Tue Apr 26 16:26:24 2016 UTC vs.
Revision 1.64 by root, Fri Nov 25 23:37:27 2016 UTC

64 64
65package CBOR::XS; 65package CBOR::XS;
66 66
67use common::sense; 67use common::sense;
68 68
69our $VERSION = 1.5; 69our $VERSION = 1.51;
70our @ISA = qw(Exporter); 70our @ISA = qw(Exporter);
71 71
72our @EXPORT = qw(encode_cbor decode_cbor); 72our @EXPORT = qw(encode_cbor decode_cbor);
73 73
74use Exporter; 74use Exporter;
180reference to the earlier value. 180reference to the earlier value.
181 181
182This means that such values will only be encoded once, and will not result 182This means that such values will only be encoded once, and will not result
183in a deep cloning of the value on decode, in decoders supporting the value 183in a deep cloning of the value on decode, in decoders supporting the value
184sharing extension. This also makes it possible to encode cyclic data 184sharing extension. This also makes it possible to encode cyclic data
185structures (which need C<allow_cycles> to ne enabled to be decoded by this 185structures (which need C<allow_cycles> to be enabled to be decoded by this
186module). 186module).
187 187
188It is recommended to leave it off unless you know your 188It is recommended to leave it off unless you know your
189communication partner supports the value sharing extensions to CBOR 189communication partner supports the value sharing extensions to CBOR
190(L<http://cbor.schmorp.de/value-sharing>), as without decoder support, the 190(L<http://cbor.schmorp.de/value-sharing>), as without decoder support, the
440 440
441Resets the incremental decoder. This throws away any saved state, so that 441Resets the incremental decoder. This throws away any saved state, so that
442subsequent calls to C<incr_parse> or C<incr_parse_multiple> start to parse 442subsequent calls to C<incr_parse> or C<incr_parse_multiple> start to parse
443a new CBOR value from the beginning of the C<$buffer> again. 443a new CBOR value from the beginning of the C<$buffer> again.
444 444
445This method can be caled at any time, but it I<must> be called if you want 445This method can be called at any time, but it I<must> be called if you want
446to change your C<$buffer> or there was a decoding error and you want to 446to change your C<$buffer> or there was a decoding error and you want to
447reuse the C<$cbor> object for future incremental parsings. 447reuse the C<$cbor> object for future incremental parsings.
448 448
449=back 449=back
450 450
985 985
986First of all, your CBOR decoder should be secure, that is, should not have 986First of all, your CBOR decoder should be secure, that is, should not have
987any buffer overflows. Obviously, this module should ensure that and I am 987any buffer overflows. Obviously, this module should ensure that and I am
988trying hard on making that true, but you never know. 988trying hard on making that true, but you never know.
989 989
990Second, CBOR::XS supports object serialisation - decoding CBOR can cause
991calls to I<any> C<THAW> method in I<any> package that exists in your
992process (that is, CBOR::XS will not try to load modules, but any existing
993C<THAW> method or function can be called, so they all have to be secure).
994
990Second, you need to avoid resource-starving attacks. That means you should 995Third, you need to avoid resource-starving attacks. That means you should
991limit the size of CBOR data you accept, or make sure then when your 996limit the size of CBOR data you accept, or make sure then when your
992resources run out, that's just fine (e.g. by using a separate process that 997resources run out, that's just fine (e.g. by using a separate process that
993can crash safely). The size of a CBOR string in octets is usually a good 998can crash safely). The size of a CBOR string in octets is usually a good
994indication of the size of the resources required to decode it into a Perl 999indication of the size of the resources required to decode it into a Perl
995structure. While CBOR::XS can check the size of the CBOR text, it might be 1000structure. While CBOR::XS can check the size of the CBOR text, it might be
996too late when you already have it in memory, so you might want to check 1001too late when you already have it in memory, so you might want to check
997the size before you accept the string. 1002the size before you accept the string.
998 1003
999Third, CBOR::XS recurses using the C stack when decoding objects and 1004Fourth, CBOR::XS recurses using the C stack when decoding objects and
1000arrays. The C stack is a limited resource: for instance, on my amd64 1005arrays. The C stack is a limited resource: for instance, on my amd64
1001machine with 8MB of stack size I can decode around 180k nested arrays but 1006machine with 8MB of stack size I can decode around 180k nested arrays but
1002only 14k nested CBOR objects (due to perl itself recursing deeply on croak 1007only 14k nested CBOR objects (due to perl itself recursing deeply on croak
1003to free the temporary). If that is exceeded, the program crashes. To be 1008to free the temporary). If that is exceeded, the program crashes. To be
1004conservative, the default nesting limit is set to 512. If your process 1009conservative, the default nesting limit is set to 512. If your process
1093 1098
1094Please refrain from using rt.cpan.org or any other bug reporting 1099Please refrain from using rt.cpan.org or any other bug reporting
1095service. I put the contact address into my modules for a reason. 1100service. I put the contact address into my modules for a reason.
1096 1101
1097=cut 1102=cut
1103
1104# clumsy hv_store-in-perl
1105sub _hv_store {
1106 $_[0]{$_[1]} = $_[2];
1107}
1098 1108
1099our %FILTER = ( 1109our %FILTER = (
1100 0 => sub { # rfc4287 datetime, utf-8 1110 0 => sub { # rfc4287 datetime, utf-8
1101 require Time::Piece; 1111 require Time::Piece;
1102 # Time::Piece::Strptime uses the "incredibly flexible date parsing routine" 1112 # Time::Piece::Strptime uses the "incredibly flexible date parsing routine"

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines