bnoordhuis/node-mmap

Problem with Buffer.copy()

Closed this issue · 2 comments

avz commented

Hi, I found problem with Buffer.copy() on buffer, returned by mmap().
Node version: v0.4.11, npm module version 0.0.3

mmap.js:

var mmap = require('mmap')
var fs = require('fs')

var fd = fs.openSync('/tmp/test', 'w+')
var size = 1024
fs.truncateSync(fd, size)

var buffer = mmap.map(size, mmap.PROT_READ | mmap.PROT_WRITE, mmap.MAP_SHARED, fd, 0)
var source = new Buffer(size)

source.copy(buffer)

Result

# node mmap.js

node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
TypeError: First arg should be a Buffer
    at Buffer.copy (buffer.js:364:22)
    at Object.<anonymous> (/tmp/mmap.js:11:8)
    at Module._compile (module.js:402:26)
    at Object..js (module.js:408:10)
    at Module.load (module.js:334:31)
    at Function._load (module.js:293:12)
    at Array.<anonymous> (module.js:421:10)
    at EventEmitter._tickCallback (node.js:126:26)

I added a fix in 09146e9 that passes your test case. However, I added a test that maps /dev/zero and it makes 0.4.x and 0.5.x crash inside memmove with an out of bounds pointer. WIP.

avz commented

I think it is no longer relevant