miyako / console-rsvg-convert

rsvg-convert clone
52 stars 8 forks source link

Crash when providing output filename without path #3

Closed relikd closed 3 years ago

relikd commented 3 years ago

Hi, and thanks for your project and the time you put in it :)

Found an interesting bug. The output option does only work if it is a proper path. Passing the filename only will result in a crash (see below). As a workaround it suffices to prepend ./ before the filename. Still, I think this could be fixed 😃

2020-11-13 01:12:54.266 rsvg[81026:1193264] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSFileManager fileSystemRepresentationWithPath:]: nil or empty path argument'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff35ed0727 __exceptionPreprocess + 250
    1   libobjc.A.dylib                     0x00007fff6edd8a9e objc_exception_throw + 48
    2   Foundation                          0x00007fff384bcbba -[NSFileManager fileSystemRepresentationWithPath:] + 595
    3   rsvg                                0x0000000103f7499c _Z20create_parent_folderPKc + 92
    4   rsvg                                0x0000000103f74224 _Z12rsvg_convertiPPc + 1299
    5   rsvg                                0x0000000103f73d0d main + 9
    6   libdyld.dylib                       0x00007fff6ff78cc9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
zsh: abort      rsvg -f pdf icon-source.svg -o out.pdf

macOS 10.15.7, console-rsvg-convert v2.1

miyako commented 3 years ago

The code blindly calls [NSString stringByDeletingLastPathComponent] so I guess it will crash if the path is made of 0 or 1 components.

For what it's worth, I've added a simple check of [NSString pathComponents].count.

https://github.com/miyako/console-rsvg-convert/releases/tag/2.1.1