Random geek moment of the day! Spent some time today trying to use the Linux bash shell to do some image processing, and was having … /1
— Charles Johnson (@Green_Footballs) August 25, 2016
lots of weird problems that didn’t actually throw errors. After tearing some hair out, I realized what was happening. I was trying … /2
— Charles Johnson (@Green_Footballs) August 25, 2016
to read an image file into a shell variable, then run several ImageMagick operations on that variable in succession. The problem is … /3
— Charles Johnson (@Green_Footballs) August 25, 2016
that shell variables don’t deal well at all with null bytes - and almost any image is guaranteed to contain null bytes. The bash … /4
— Charles Johnson (@Green_Footballs) August 25, 2016
shell uses C-style strings, which are terminated with - you guessed it - null bytes. So the shell variable was actually being … /5
— Charles Johnson (@Green_Footballs) August 25, 2016
truncated at the point where the null byte occurred. Ouch, that hurts. I ended up switching the code to use PHP’s Imagick extension … /6
— Charles Johnson (@Green_Footballs) August 25, 2016
instead and now all is well. /7
— Charles Johnson (@Green_Footballs) August 25, 2016