Ticket #1665 (closed bug: fixed)

Opened 5 years ago

Last modified 5 years ago

Pointer error when adding UTF-8 characters to StringBuilder byte-by-byte

Reported by: masak Owned by:
Priority: major Milestone:
Component: none Version: 2.4.0
Severity: medium Keywords:
Cc: Language:
Patch status: Platform:

Description

The below snippet blows up when it tried to create the string "ö" by gluing together two bytes in a StringBuilder.

This bug is currently blocking some parts of my GSoC work on Rakudo.

pmichaud@plum:~/parrot/trunk$ cat x.pir
.sub 'main'
    .local pmc list
    list = new 'ResizablePMCArray'
    push list, 195
    push list, 182

    .local pmc iterator
    iterator = iter list
    .local pmc sb
    sb = new 'StringBuilder'
    sb = unicode:""
    loop:
      unless iterator goto done
      $P1 = shift iterator
      $I1 = $P1
      $S1 = chr $I1
      sb .= $S1
      goto loop
    done:
      $P99 = sb
      say $P99
.end
pmichaud@plum:~/parrot/trunk$ ./parrot x.pir
*** glibc detected *** ./parrot: realloc(): invalid pointer: 0x0000000000e49928 ***
======= Backtrace: =========
/lib/libc.so.6(+0x775b6)[0x7f9c021c85b6]
/lib/libc.so.6(realloc+0x352)[0x7f9c021cf2e2]
/home/pmichaud/parrot/trunk/blib/lib/libparrot.so.2.4.0(+0x85cb4)[0x7f9c04c46cb4]
/home/pmichaud/parrot/trunk/blib/lib/libparrot.so.2.4.0(+0x147337)[0x7f9c04d08337]
/home/pmichaud/parrot/trunk/blib/lib/libparrot.so.2.4.0(+0x59eff)[0x7f9c04c1aeff]
/home/pmichaud/parrot/trunk/blib/lib/libparrot.so.2.4.0(+0xb6901)[0x7f9c04c77901]
/home/pmichaud/parrot/trunk/blib/lib/libparrot.so.2.4.0(+0xb5ebd)[0x7f9c04c76ebd]
/home/pmichaud/parrot/trunk/blib/lib/libparrot.so.2.4.0(+0x8eb0e)[0x7f9c04c4fb0e]
/home/pmichaud/parrot/trunk/blib/lib/libparrot.so.2.4.0(Parrot_pcc_invoke_from_sig_object+0xb1)[0x7f9c04c4b871]
/home/pmichaud/parrot/trunk/blib/lib/libparrot.so.2.4.0(Parrot_pcc_invoke_sub_from_c_args+0xeb)[0x7f9c04c4b9ab]
/home/pmichaud/parrot/trunk/blib/lib/libparrot.so.2.4.0(imcc_run+0x76c)[0x7f9c04d194ec]
./parrot[0x4018c6]
/lib/libc.so.6(__libc_start_main+0xfd)[0x7f9c0216fc4d]
./parrot[0x401219]
======= Memory map: ========
00400000-00409000 r-xp 00000000 08:07 116591                             /home/pmichaud/parrot/trunk/parrot
00609000-0060a000 r--p 00009000 08:07 116591                             /home/pmichaud/parrot/trunk/parrot
0060a000-0060b000 rw-p 0000a000 08:07 116591                             /home/pmichaud/parrot/trunk/parrot
00e48000-00f5c000 rw-p 00000000 00:00 0                                  [heap]
7f9c01f0e000-7f9c01f4c000 r-xp 00000000 08:06 32674                      /lib/libncurses.so.5.7
7f9c01f4c000-7f9c0214c000 ---p 0003e000 08:06 32674                      /lib/libncurses.so.5.7
7f9c0214c000-7f9c02150000 r--p 0003e000 08:06 32674                      /lib/libncurses.so.5.7
7f9c02150000-7f9c02151000 rw-p 00042000 08:06 32674                      /lib/libncurses.so.5.7
7f9c02151000-7f9c022c9000 r-xp 00000000 08:06 32621                      /lib/libc-2.11.1.so
7f9c022c9000-7f9c024c9000 ---p 00178000 08:06 32621                      /lib/libc-2.11.1.so
7f9c024c9000-7f9c024cd000 r--p 00178000 08:06 32621                      /lib/libc-2.11.1.so
7f9c024cd000-7f9c024ce000 rw-p 0017c000 08:06 32621                      /lib/libc-2.11.1.so
7f9c024ce000-7f9c024d3000 rw-p 00000000 00:00 0 
7f9c024d3000-7f9c024e9000 r-xp 00000000 08:06 32655                      /lib/libgcc_s.so.1
7f9c024e9000-7f9c026e8000 ---p 00016000 08:06 32655                      /lib/libgcc_s.so.1
7f9c026e8000-7f9c026e9000 r--p 00015000 08:06 32655                      /lib/libgcc_s.so.1
7f9c026e9000-7f9c026ea000 rw-p 00016000 08:06 32655                      /lib/libgcc_s.so.1
7f9c026ea000-7f9c027e0000 r-xp 00000000 08:06 165455                     /usr/lib/libstdc++.so.6.0.13
7f9c027e0000-7f9c029e0000 ---p 000f6000 08:06 165455                     /usr/lib/libstdc++.so.6.0.13
7f9c029e0000-7f9c029e7000 r--p 000f6000 08:06 165455                     /usr/lib/libstdc++.so.6.0.13
7f9c029e7000-7f9c029e9000 rw-p 000fd000 08:06 165455                     /usr/lib/libstdc++.so.6.0.13
7f9c029e9000-7f9c029fe000 rw-p 00000000 00:00 0 
7f9c029fe000-7f9c02a34000 r-xp 00000000 08:06 32594                      /lib/libreadline.so.5.2
7f9c02a34000-7f9c02c33000 ---p 00036000 08:06 32594                      /lib/libreadline.so.5.2
7f9c02c33000-7f9c02c35000 r--p 00035000 08:06 32594                      /lib/libreadline.so.5.2
7f9c02c35000-7f9c02c3b000 rw-p 00037000 08:06 32594                      /lib/libreadline.so.5.2
7f9c02c3b000-7f9c02c3c000 rw-p 00000000 00:00 0 
7f9c02c3c000-7f9c02c43000 r-xp 00000000 08:06 32735                      /lib/librt-2.11.1.so
7f9c02c43000-7f9c02e42000 ---p 00007000 08:06 32735                      /lib/librt-2.11.1.so
7f9c02e42000-7f9c02e43000 r--p 00006000 08:06 32735                      /lib/librt-2.11.1.so
7f9c02e43000-7f9c02e44000 rw-p 00007000 08:06 32735                      /lib/librt-2.11.1.so
7f9c02e44000-7f9c02e4d000 r-xp 00000000 08:06 32629                      /lib/libcrypt-2.11.1.so
7f9c02e4d000-7f9c0304d000 ---p 00009000 08:06 32629                      /lib/libcrypt-2.11.1.so
7f9c0304d000-7f9c0304e000 r--p 00009000 08:06 32629                      /lib/libcrypt-2.11.1.so
7f9c0304e000-7f9c0304f000 rw-p 0000a000 08:06 32629                      /lib/libcrypt-2.11.1.so
7f9c0304f000-7f9c0307d000 rw-p 00000000 00:00 0 
7f9c0307d000-7f9c03095000 r-xp 00000000 08:06 32729                      /lib/libpthread-2.11.1.so
7f9c03095000-7f9c03294000 ---p 00018000 08:06 32729                      /lib/libpthread-2.11.1.so
7f9c03294000-7f9c03295000 r--p 00017000 08:06 32729                      /lib/libpthread-2.11.1.so
7f9c03295000-7f9c03296000 rw-p 00018000 08:06 32729                      /lib/libpthread-2.11.1.so
7f9c03296000-7f9c0329a000 rw-p 00000000 00:00 0 
7f9c0329a000-7f9c0329c000 r-xp 00000000 08:06 32635                      /lib/libdl-2.11.1.so
7f9c0329c000-7f9c0349c000 ---p 00002000 08:06 32635                      /lib/libdl-2.11.1.so
7f9c0349c000-7f9c0349d000 r--p 00002000 08:06 32635                      /lib/libdl-2.11.1.so
7f9c0349d000-7f9c0349e000 rw-p 00003000 08:06 32635                      /lib/libdl-2.11.1.so
7f9c0349e000-7f9c03520000 r-xp 00000000 08:06 32670                      /lib/libm-2.11.1.so
7f9c03520000-7f9c0371f000 ---p 00082000 08:06 32670                      /lib/libm-2.11.1.so
7f9c0371f000-7f9c03720000 r--p 00081000 08:06 32670                      /lib/libm-2.11.1.so
7f9c03720000-7f9c03721000 rw-p 00082000 08:06 32670                      /lib/libm-2.11.1.so
7f9c03721000-7f9c04666000 r--p 00000000 08:06 164868                     /usr/lib/libicudata.so.42.1
7f9c04666000-7f9c04865000 ---p 00f45000 08:06 164868                     /usr/lib/libicudata.so.42.1
7f9c04865000-7f9c04866000 r--p 00f44000 08:06 164868                     /usr/lib/libicudata.so.42.1
7f9c04866000-7f9c049ae000 r-xp 00000000 08:06 164880                     /usr/lib/libicuuc.so.42.1
7f9c049ae000-7f9c04bae000 ---p 00148000 08:06 164880                     /usr/lib/libicuuc.so.42.1
7f9c04bae000-7f9c04bbc000 r--p 00148000 08:06 164880                     /usr/lib/libicuuc.so.42.1
7f9c04bbc000-7f9c04bbf000 rw-p 00156000 08:06 164880                     /usr/lib/libicuuc.so.42.1
7f9c04bbf000-7f9c04bc1000 rw-p 00000000 00:00 0 
7f9c04bc1000-7f9c04d89000 r-xp 00000000 08:07 188612                     /home/pmichaud/parrot/trunk/blib/lib/libparrot.so.2.4.0Aborted
pmichaud@plum:~/parrot/trunk$

Change History

Changed 5 years ago by bacek

  • status changed from new to closed
  • resolution set to fixed

Fixed in r47086. Test added. Resolving ticket.

Note: See TracTickets for help on using tickets.