From fa62ddeba57319c9b691ecd669d317fe7c660980 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Tue, 31 Mar 2015 15:44:43 -0500 Subject: [svn-r26681] Merge r26677 from trunk. HDFFV-8957: h52gif crashes when run against one of our own examples The tool claimed it could handle 24bit images but there was no code to handle it. (or might be there were but was removed by previous revisions.) Also discovered that it does not accept multiple images nor -p for palette as its user document and online help message indicated. Solution: Added code to verify dimension sizes are within 8 bit raster images limit and added tests to verify the tools correctness. Need to update user document tool. Tested: h5committested. --- MANIFEST | 2 + hl/tools/gif2h5/h52giftest.sh.in | 75 ++++++++++++++++++++++----------- hl/tools/gif2h5/hdf2gif.c | 13 ++++++ hl/tools/gif2h5/testfiles/REAMDE | 6 +++ hl/tools/gif2h5/testfiles/ex_image2.h5 | Bin 0 -> 224533 bytes release_docs/RELEASE.txt | 2 + 6 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 hl/tools/gif2h5/testfiles/REAMDE create mode 100644 hl/tools/gif2h5/testfiles/ex_image2.h5 diff --git a/MANIFEST b/MANIFEST index 17f369c..c1f968c 100644 --- a/MANIFEST +++ b/MANIFEST @@ -2195,6 +2195,8 @@ ./hl/tools/gif2h5/writehdf.c ./hl/tools/gif2h5/h52gifgentst.c ./hl/tools/gif2h5/h52giftest.sh.in +./hl/tools/gif2h5/testfiles/REAMDE +./hl/tools/gif2h5/testfiles/ex_image2.h5 ./hl/tools/gif2h5/testfiles/image1.gif ./hl/tools/gif2h5/testfiles/h52giftst.h5 diff --git a/hl/tools/gif2h5/h52giftest.sh.in b/hl/tools/gif2h5/h52giftest.sh.in index 186b369..7aec219 100644 --- a/hl/tools/gif2h5/h52giftest.sh.in +++ b/hl/tools/gif2h5/h52giftest.sh.in @@ -18,6 +18,7 @@ TESTFILE1="$srcdir/testfiles/h52giftst.h5" TESTFILE2="$srcdir/testfiles/image1.gif" +TESTFILE3="$srcdir/testfiles/ex_image2.h5" # initialize errors variable errors=0 @@ -29,45 +30,69 @@ TESTING() { -TOOLTEST1() +# Verify the test runs with success (return code is 0) +TOOLTEST() { - $RUNSERIAL ./h52gif $* - - RET=$? - if [ $RET != 0 ] ; then - echo "*FAILED*" - errors="` expr $errors + 1 `"; - else - echo " PASSED" - fi + # for now, discard any error messages generated. + $RUNSERIAL $* > /dev/null 2>&1 + + RET=$? + if [ $RET = 0 ] ; then + echo " PASSED" + else + echo "*FAILED*" + errors="` expr $errors + 1 `"; + fi } -TOOLTEST2() +# Verify the test runs with failure (return code is not 0) +# Use for testing if tool can handle error conditions like +# illegal input, bad arguments, exeeding limits, ... +TOOLTESTFAIL() { - $RUNSERIAL ./gif2h5 $* - - RET=$? - if [ $RET != 0 ] ; then - echo "*FAILED*" - errors="` expr $errors + 1 `"; - else - echo " PASSED" - fi + # for now, discard any error messages generated. + $RUNSERIAL $* > /dev/null 2>&1 + + RET=$? + if [ $RET != 0 ] ; then + echo " PASSED" + else + echo "*FAILED*" + errors="` expr $errors + 1 `"; + fi } +# Positive tests for gif2h5 +echo "**validate the gif2h5 tool processes input correctly..." +TESTING "./gif2h5 image1.gif image1.h5" +TOOLTEST ./gif2h5 $TESTFILE2 image1.h5 +echo "" +# Positive tests for h52gif +echo "**validate the h52gif tool processes input correctly..." TESTING "./h52gif h52giftst.h5 image1.gif -i image" -TOOLTEST1 $TESTFILE1 image1.gif -i image -TESTING "./gif2h5 image1.gif image1.h5" -TOOLTEST2 $TESTFILE2 image1.h5 +TOOLTEST ./h52gif $TESTFILE1 image1.gif -i image +echo "" +# Negative tests. +echo "**verify the the h52gif tool handle error conditions correctly..." +# nonexisting dataset name +TESTING "./h52gif h52giftst.h5 image.gif -i nosuch_image" +TOOLTESTFAIL "./h52gif $TESTFILE1 image.gif -i nosuch_image" +# this test should have failed but it did not. Comment it out for now. +#TESTING "./h52gif h52giftst.h5 image.gif -i palette" +#TOOLTESTFAIL "./h52gif $TESTFILE1 image.gif -i palette" +TESTING "./h52gif h52giftst.h5 image24.gif -i image24bitpixel" +TOOLTESTFAIL "./h52gif $TESTFILE3 image24.gif -i image24bitpixel" +echo "" +# all done. summarize results. if test $errors -eq 0 ; then - echo "All h52gif tests passed." + echo "All gif2h5 and h52gif tests passed." exit 0 else - echo "h52gif tests failed with $errors errors." + echo "Some gif2h5 or h52gif tests failed with $errors errors." exit 1 fi diff --git a/hl/tools/gif2h5/hdf2gif.c b/hl/tools/gif2h5/hdf2gif.c index fe79975..5c342ba 100644 --- a/hl/tools/gif2h5/hdf2gif.c +++ b/hl/tools/gif2h5/hdf2gif.c @@ -20,6 +20,8 @@ #include "h5tools.h" #include "h5tools_utils.h" +#define IMAGE_WIDTH_MAX 65535 /* unsigned 16bits integer */ +#define IMAGE_HEIGHT_MAX 65535 /* unsigned 16bits integer */ int EndianOrder; @@ -147,6 +149,17 @@ int main(int argc , char **argv) if ( H5IMget_image_info( fid, image_name, &width, &height, &planes, interlace, &npals ) < 0 ) goto out; + if (width > IMAGE_WIDTH_MAX || height > IMAGE_HEIGHT_MAX){ + fprintf(stderr, "HDF5 image is too large. Limit is %d by %d.\n", IMAGE_WIDTH_MAX, IMAGE_HEIGHT_MAX); + goto out; + } + + /* tool can handle single plane images only. */ + if (planes > 1){ + fprintf(stderr, "Cannot handle multiple planes image\n"); + goto out; + } + Image = (BYTE*) malloc( (size_t) width * (size_t) height ); if ( H5IMread_image( fid, image_name, Image ) < 0 ) diff --git a/hl/tools/gif2h5/testfiles/REAMDE b/hl/tools/gif2h5/testfiles/REAMDE new file mode 100644 index 0000000..a428d47 --- /dev/null +++ b/hl/tools/gif2h5/testfiles/REAMDE @@ -0,0 +1,6 @@ +ex_image2.h5 + Generated by hl/examples/ex_image2.c +5giftst.h5: + Generated by ../h52gifgentst.c +image1.gif: + To be determined. diff --git a/hl/tools/gif2h5/testfiles/ex_image2.h5 b/hl/tools/gif2h5/testfiles/ex_image2.h5 new file mode 100644 index 0000000..a36df1b Binary files /dev/null and b/hl/tools/gif2h5/testfiles/ex_image2.h5 differ diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index c3738b7..384e4ee 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -315,6 +315,8 @@ Bug Fixes since HDF5-1.8.14 Tools ----- + - Fixed h52gif crashed if instructed to convert images other than 8bit + images. (AKC - 2015/03/31, HDFFV-8957) - Benchpar.c in perform is retired. (AKC - 2014/12/19, HDFFV-8156) - The perform directory is moved to tools/perform for easier maintenance. (AKC - 2014/12/17, HDFFV-9046) -- cgit v0.12