Skip to content

Commit

Permalink
Added a test of a bad write.
Browse files Browse the repository at this point in the history
This is done by writing to a pipe and closing it early.

TESTING
  • Loading branch information
dfandrich committed Feb 28, 2019
1 parent d6fe9fb commit 9fd03f3
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions test/check-no-seek.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/bin/sh
set -x
# Check that operations on files that can't seek are cleanly handled.

. ./check-vars.sh

readonly tmpfifo="check-no-seek.tmp"
readonly tmpfifo="check-no-seek-fifo.tmp"
readonly srcimg="$SRCDIR/testdata/no-exif.jpg"
readonly tmpfile="check-no-seek.tmp"

rm -f "${tmpfifo}"
mkfifo "${tmpfifo}" || { echo "Could not create FIFO; skipping test"; exit 0; }
Expand All @@ -13,12 +15,28 @@ echo Check that write to FIFO succeeds
# Throw away any data written to the FIFO
cat ${tmpfifo} > /dev/null &
$EXIFEXE --create-exif -o "${tmpfifo}" >/dev/null
test $? -eq 0 || { echo Incorrect return code $? not 0; exit 1; }
test $? -eq 0 || { echo Incorrect return code, expected 0; exit 1; }
# Kill the cat and wait for it to exit
kill $!
wait $! >/dev/null 2>&1

echo Check that write to FIFO with early close fails cleanly
# Throw away the first byte of data written to the FIFO then close the FIFO,
# triggering a write error in exif. A FIFO in all tested OSes buffers up to
# 64KiB of data, so the write needs to be larger than that to invoke a write
# failure. This is done by writing a large thumbnail to bring the total JPEG
# size above that. It can't be too large, however, or it would exceed the
# 64MiB limit of the EXIF portion of the file.
dd if=/dev/zero of="${tmpfile}" bs=65200 count=1 >/dev/null 2>&1
dd if="${tmpfifo}" of=/dev/null bs=1 count=1 >/dev/null 2>&1 &
$EXIFEXE --create-exif --insert-thumbnail="${tmpfile}" -o "${tmpfifo}" "${srcimg}" >/dev/null
test $? -eq 1 || { echo Incorrect return code, expected 1; exit 1; }
# Make sure dd is killed and wait for it to exit
kill $!
wait $!
# The FIFO is already cleared at this point

echo Check that read of image from FIFO fails cleanly
echo Check that read of image from unseekable FIFO fails cleanly
# Reading from an image requires its size which can't be determined from a
# FIFO. exif should detect this and cleanly exit. It should really be
# fixed so it doesn't need the size in advance.
Expand All @@ -27,18 +45,19 @@ echo Check that read of image from FIFO fails cleanly
# the second time.
(cat "${srcimg}" >"${tmpfifo}"; sleep 1; cat "${srcimg}" >"${tmpfifo}") &
$EXIFEXE --create-exif -o /dev/null "${tmpfifo}" >/dev/null
test $? -eq 1 || { echo Incorrect return code $? not 1; exit 1; }
test $? -eq 1 || { echo Incorrect return code, expected 1; exit 1; }
# Kill cat and wait for it to exit
kill $!
wait $! >/dev/null 2>&1

echo Check that read of thumbnail from FIFO fails cleanly
echo Check that read of thumbnail from unseekable FIFO fails cleanly
# Same situation as the previous test, but on the thumbnail read path.
(cat "${srcimg}" >"${tmpfifo}"; sleep 1; cat "${srcimg}" >"${tmpfifo}") &
$EXIFEXE --create-exif --insert-thumbnail="${tmpfifo}" -o /dev/null
test $? -eq 1 || { echo Incorrect return code $? not 1; exit 1; }
$EXIFEXE --create-exif --insert-thumbnail="${tmpfifo}" -o /dev/null "${srcimg}"
test $? -eq 1 || { echo Incorrect return code, expected 1; exit 1; }
# Kill the cat and wait for it to exit
kill $!
wait $!
wait $! >/dev/null 2>&1

echo PASSED
rm -f "${tmpfifo}"
rm -f "${tmpfifo}" "${tmpfile}"

0 comments on commit 9fd03f3

Please sign in to comment.