Dangerous usage of read() in ReadBlob()
Posted: 2013-04-25T04:46:16-07:00
This code in magick/blob.c can legally return any count as a result:
According to manual:
Actually this can happen independent of I/O type, only it must be slow enough. I see no solution but using fread() here.
Code: Select all
2789 case StandardStream:
2790 {
2791 count=read(fileno(image->blob->file_info.file),q,length);
2792 break;
2793 }
This command line performs on GNU/Linux successfully for lower N, always fails for higher N and behaves randomly on N between 50 and 200, depending on system speed. See two convert calls that work with same data, but gain different results:It is not an error if this number is smaller than the number of bytes requested
Code: Select all
$ export N=150; head -c $(($N*$N*3)) /dev/urandom | tee img | convert -depth 8 -size ${N}x${N} rgb:- o.raw
convert: unexpected end-of-file `-': No such file or directory @ error/rgb.c/ReadRGBImage/231.
$ cat img | convert -depth 8 -size ${N}x${N} rgb:- o.raw
$ ls -l o.raw
-rw-r--r-- 1 george george 67500 Apr 25 15:43 o.raw