Skip to content

Commit

Permalink
check bpm is not an empty string
Browse files Browse the repository at this point in the history
if bpm is empty the next operation, atoi, will segfault, adds check and defaults to 0
  • Loading branch information
heapwolf committed Oct 24, 2016
1 parent 99ae6ea commit 507a307
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "taglib2",
"version": "2.6.0",
"version": "2.6.1",
"description": "taglib version2 bindings",
"scripts": {
"test": "tape ./tests",
Expand Down
10 changes: 8 additions & 2 deletions src/taglib2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,16 @@ NAN_METHOD(readTagsSync) {
TagLib::ByteVector vec = sl.data(TagLib::String::UTF8);
char* s = vec.data();

int i = 0;

if (s) {
i = atoi(s);
}

obj->Set(
Nan::New("bpm").ToLocalChecked(),
Nan::New<v8::Integer>(atoi(s))
);
Nan::New<v8::Integer>(i)
);
}

if (map.contains("COMPOSER")) {
Expand Down
Binary file modified tests/fixtures/sample-output.mp3
Binary file not shown.
32 changes: 16 additions & 16 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@ const fs = require('fs')
const taglib2 = require('../index')
const test = require('tape')
const mkdirp = require('mkdirp')
const path = require('path')
const rimraf = require('rimraf')

const TMP_PATH = __dirname + '/tmp'
const FIXTURES_PATH = __dirname + '/fixtures'
const TMP_PATH = path.join(__dirname, '/tmp')
const FIXTURES_PATH = path.join(__dirname, '/fixtures')

test('setup', assert => {
try { fs.statSync(TMP_PATH) }
catch(_) { mkdirp.sync(TMP_PATH) }
try {
fs.statSync(TMP_PATH)
} catch (_) {
mkdirp.sync(TMP_PATH)
}
assert.end()
})

rimraf.sync(TMP_PATH + '/*')

test('sync write/read', assert => {

function getRandomYear() {
const date = new Date
function getRandomYear () {
const date = new Date()
const from = date.setFullYear(1877, 0, 1)
const to = (new Date).getTime()
const to = (new Date()).getTime()
return new Date(from + Math.random() * (to - from)).getFullYear()
}

Expand Down Expand Up @@ -49,12 +52,12 @@ test('sync write/read', assert => {
comment: 'comment' + rn,
genre: 'genre' + rn,
year: rn_year,
//track: 3 + rn,
// track: 3 + rn,
tracknumber: '3/' + rn,
discnumber: '1/' + rn,
composer: 'composer' + rn,
bpm: parseInt(120, 10),
//mimetype: 'image/jpeg',
// mimetype: 'image/jpeg',
pictures: [{ mimetype: '', picture: imagefile }]
})

Expand All @@ -76,7 +79,7 @@ test('sync write/read', assert => {
assert.equal(tags.year, parseInt(rn_year, 10))
assert.equal(tags.discnumber, '1/' + rn)
assert.equal(tags.composer, 'composer' + rn)
//assert.equal(tags.track, 3 + rn)
// assert.equal(tags.track, 3 + rn)
assert.equal(tags.tracknumber, '3/' + rn)

const tmpImagepath = TMP_PATH + '/sample.jpg'
Expand All @@ -97,7 +100,6 @@ test('sync write/read', assert => {
})

test('sync write/read m4a + jpg', assert => {

const rn = Math.floor(Math.random() * 100)
const rn_year = Math.floor(Math.random() * 1000)

Expand All @@ -111,9 +113,9 @@ test('sync write/read m4a + jpg', assert => {
const r = taglib2.writeTagsSync(audiopath, {
pictures: [{
mimetype: 'image/jpeg',
picture: imagefile
picture: imagefile
}]
})
})

assert.comment('read the tags from the new file')
const tags = taglib2.readTagsSync(audiopath)
Expand All @@ -132,9 +134,7 @@ test('sync write/read m4a + jpg', assert => {
assert.end()
})


test('sync write/read m4a + png', assert => {

const rn = Math.floor(Math.random() * 100)
const rn_year = Math.floor(Math.random() * 1000)

Expand Down

0 comments on commit 507a307

Please sign in to comment.