:begin

YAML, Net::DNS, UTF8
Steffen Ullrich, GeNUA mbH
Deutscher Perl-Workshop 2012, Erlangen

Background

Bummer!

Exception: incomplete data at ...Net/DNS/RR.pm line 565.
 caught at ...Net/DNS/RR.pm line 517

 557  my ($name, $index) = Net::DNS::Packet::dn_expand($data, $offset);
 558  die 'Exception: corrupt or incomplete data' unless $index;
 559 
 560  my $rdindex = $index + PACKED_LENGTH;
 561  die 'Exception: incomplete data' if length $$data < $rdindex;
 562  my ($type, $class, $ttl, $rdlength) = unpack("\@$index n2 N n", $$data);
 563 
 564  my $next = $rdindex + $rdlength;
 565  die 'Exception: incomplete data' if length $$data < $next;

nach langer Zeit..

  sub dn_expand {
  #FYI    my ($packet, $offset) = @_; 
-         return dn_expand_XS(@_) if $Net::DNS::HAVE_XS;
+ #       return dn_expand_XS(@_) if $Net::DNS::HAVE_XS;
  #       warn "USING PURE PERL dn_expand()\n";
          return dn_expand_PP(@_, {} );   # $packet, $offset, anonymous hash
  }

strategische printfs

   void
   dn_expand_XS(sv_buf, offset)
       ...
       buf = (u_char *) SvPV(sv_buf, len);
       pos = netdns_dn_expand(buf, buf+len , buf+offset, 
          &name[0], MAXDNAME);

Dump, Devel::Peek

   SV = PV(0x1c82bc8) at 0x1ca1120
   FLAGS = (PADMY,POK,pPOK,UTF8)
   ...
   CUR = 120

YAML Changelog

   version: 0.71
   date: Sun Jan 3 12:25:00 AEST 2010
   changes:
   - Set file encoding to UTF-8 in LoadFile/DumpFile (RT#25434) ...
   ...

POC

   use Encode;
   my $x = 'ab';
   Encode::_utf8_on($x);
   $x .= "cd\x8a\x83ab";
   Devel::Peek::Dump($x);

Resultat

   SV = PV(0x1c82bc8) at 0x1ca1120
   REFCNT = 1
   FLAGS = (PADMY,POK,pPOK,UTF8)
   PV = 0x1c9b6a0 "abcd\302\212\302\203ab"\0 [UTF8 "abcd\x{8a}\x{83}ab"]
   CUR = 10     <<<< length($x) == 8!
   LEN = 16

Zusammenfassung