Skip to content

Instantly share code, notes, and snippets.

@adalinesimonian
Created August 20, 2015 07:16
Show Gist options
  • Save adalinesimonian/522d8ff3edb2fd3ebaf7 to your computer and use it in GitHub Desktop.
Save adalinesimonian/522d8ff3edb2fd3ebaf7 to your computer and use it in GitHub Desktop.
Segfault when writing to Buffer using UCS2 encoding
vartan@Vartan-Desktop  ~/Code/Practice/buffer-segfault  gdb --args node main.js
GNU gdb (Ubuntu 7.9-1ubuntu1) 7.9
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from node...(no debugging symbols found)...done.
(gdb) run
Starting program: /usr/bin/node main.js
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Text to write: 12345678901234567890123456789012345678901234567890
50 characters
=== Writing using base64 encoding
Required buffer length: 37
Wrote 37 bytes
<Buffer d7 6d f8 e7 ae fc f7 4d 76 df 8e 7a ef cf 74 d7 6d f8 e7 ae fc f7 4d 76 df 8e 7a ef cf 74 d7 6d f8 e7 ae fc f7>
=== Writing using binary encoding
Required buffer length: 50
Wrote 50 bytes
<Buffer 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30>
=== Writing using utf8 encoding
Required buffer length: 50
Wrote 50 bytes
<Buffer 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30>
=== Writing using hex encoding
Required buffer length: 25
Wrote 25 bytes
<Buffer 12 34 56 78 90 12 34 56 78 90 12 34 56 78 90 12 34 56 78 90 12 34 56 78 90>
=== Writing using ascii encoding
Required buffer length: 50
Wrote 50 bytes
<Buffer 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30>
=== Writing using ucs2 encoding
Required buffer length: 100
[New Thread 0x7ffff53b4700 (LWP 2518)]
[New Thread 0x7ffff5bb5700 (LWP 2517)]
[New Thread 0x7ffff63b6700 (LWP 2516)]
[New Thread 0x7ffff6bb7700 (LWP 2515)]
Program received signal SIGSEGV, Segmentation fault.
0x0000000000b6c595 in void v8::internal::String::WriteToFlat<unsigned short>(v8::internal::String*, unsigned short*, int, int) ()
(gdb) backtrace
#0 0x0000000000b6c595 in void v8::internal::String::WriteToFlat<unsigned short>(v8::internal::String*, unsigned short*, int, int) ()
#1 0x000000000085124a in v8::String::Write(unsigned short*, int, int, int) const ()
#2 0x0000000000d9980a in node::StringBytes::Write(v8::Isolate*, char*, unsigned long, v8::Local<v8::Value>, node::encoding, int*) ()
#3 0x0000000000d74de8 in void node::Buffer::StringWrite<(node::encoding)3>(v8::FunctionCallbackInfo<v8::Value> const&) ()
#4 0x00000000008653f7 in v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) ()
#5 0x000000000088d5f5 in ?? ()
#6 0x000000000088da6d in ?? ()
#7 0x00000127ca2060bb in ?? ()
#8 0x000020f3b2a74ac1 in ?? ()
#9 0x00000127ca206001 in ?? ()
#10 0x00007fffffffd0f0 in ?? ()
#11 0x00007fffffffd170 in ?? ()
#12 0x00000127ca2c81c0 in ?? ()
#13 0x000020f3b2a74ac1 in ?? ()
#14 0x0000006400000000 in ?? ()
#15 0x0000000000000000 in ?? ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment