Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SIGABRT when passing invalid format to convert #61

Merged
merged 2 commits into from
Nov 12, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/imagemagick.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,18 @@ void DoConvert(uv_work_t* req) {
}

Magick::Blob dstBlob;
image.write( &dstBlob );

try {
image.write( &dstBlob );
}
catch (std::exception& err) {
std::string message = "image.write failed with error: ";
message += err.what();
context->error = message;
return;
}
catch (...) {
context->error = std::string("unhandled error");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we be returning here as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should and we do now.

}
context->dstBlob = dstBlob;
}

Expand Down
18 changes: 18 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ function saveToFileIfDebug (buffer, file) {
}
}

test( 'convert invalid format', function (t) {
var buffer;
try {
buffer = imagemagick.convert({
srcData: require('fs').readFileSync( "test.png" ), // 58x66
width: 100,
height: 100,
quality: 80,
format: 'PNGX',
debug: debug
});
} catch (e) {
t.like( e.message, /no decode delegate for this image format/, 'err message' );
}
t.equal( buffer, undefined, 'buffer undefined' );
t.end();
});

test( 'convert invalid number of arguments', function (t) {
var error = 0;
try {
Expand Down