{"action":"created","issue":{"url":"https://api.github.com/repos/jcupitt/libvips/issues/474","repository_url":"https://api.github.com/repos/jcupitt/libvips","labels_url":"https://api.github.com/repos/jcupitt/libvips/issues/474/labels{/name}","comments_url":"https://api.github.com/repos/jcupitt/libvips/issues/474/comments","events_url":"https://api.github.com/repos/jcupitt/libvips/issues/474/events","html_url":"https://github.com/jcupitt/libvips/issues/474","id":162136150,"number":474,"title":" Premature end of JPEG file not reported correctly.","user":{"login":"DFKSingleton","id":18052758,"avatar_url":"https://avatars.githubusercontent.com/u/18052758?v=3","gravatar_id":"","url":"https://api.github.com/users/DFKSingleton","html_url":"https://github.com/DFKSingleton","followers_url":"https://api.github.com/users/DFKSingleton/followers","following_url":"https://api.github.com/users/DFKSingleton/following{/other_user}","gists_url":"https://api.github.com/users/DFKSingleton/gists{/gist_id}","starred_url":"https://api.github.com/users/DFKSingleton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DFKSingleton/subscriptions","organizations_url":"https://api.github.com/users/DFKSingleton/orgs","repos_url":"https://api.github.com/users/DFKSingleton/repos","events_url":"https://api.github.com/users/DFKSingleton/events{/privacy}","received_events_url":"https://api.github.com/users/DFKSingleton/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jcupitt/libvips/labels/bug","name":"bug","color":"e10c02"},{"url":"https://api.github.com/repos/jcupitt/libvips/labels/in%20development","name":"in development","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2016-06-24T12:25:24Z","updated_at":"2016-07-29T18:04:50Z","closed_at":null,"body":"I have a problem with JPEG files that have been truncated (or not correctly sent) from my camera to my FTP server. Not all JPEG pictures are corrupted, but I want to detect the problem in VIPS. According to the documentation for `vips_jpegload(),` it should be possible to set `\"fail\"` to `TRUE`, so that, to quote: \"_the JPEG reader fail on any warnings. This can be useful for detecting truncated files_\". Unfortunately, this does not seem to be the case as the test program below and attached test picture show. When `fail `is set to `FALSE`, then vips reports a problem on the command line. As far as I can see, the report is only produced when `vips_shutdown()` is called. When `fail `is set to `TRUE`, then no report is produced from VIPS. \r\n\r\nI have found a possible workaround that I will try - to examine the contents of `vips_error_buffer()` after the first operation on the image - `avg()` (which I do anyway). I can understand, that due to the way that VIPS caches operations on an image, the problem with the truncated file is not noticed until after the return from `VImage::new_from_file()`. It would however be nice to have a way of detecting such problems earlier or having them signalled with an exception. \r\n\r\nBest wishes\r\n\r\nDavid Singleton\r\n\r\n```\r\n/*\r\n * vipstestbadfiles_main.cpp\r\n *\r\n *  Created on: 23.06.2016\r\n *      Author: David Singleton\r\n */\r\n#include <stdio.h>\r\n#include <unistd.h>\r\n#include <string>\r\n#include <vips/vips8>\r\n\r\n#define RC_OK 0\r\n\r\nusing namespace vips;\r\n\r\nint main(int argv, char ** argc) {\r\n   printf(\"vipstestbadfiles_main started\\n\");\r\n   int iRc = vips_init(argc[0]);\r\n   if (RC_OK != iRc) {\r\n      throw VError(\"unable to start VIPS\");\r\n   }\r\n   vips_leak_set(TRUE);\r\n   {\r\n      std::string inDirName =\r\n            \"D:/Workarea/Cplusplus/VipsTestBadFiles/testdaten/\";\r\n      std::string outDirName = \"D:/Workarea/Cplusplus/VipsTestBadFiles/out/\";\r\n      const char * szTestFileName = \"006E07875254_20160623015311.jpg\";\r\n      std::string testFilePath = inDirName + szTestFileName;\r\n      std::string outFilePath = outDirName + szTestFileName;\r\n      unlink(outFilePath.c_str());\r\n      VImage testImage;\r\n      const char * szError;\r\n      do {\r\n         try {\r\n            gboolean bFail = TRUE;\r\n            testImage = VImage::new_from_file(testFilePath.c_str(),\r\n                  VImage::option()->set(\"fail\", bFail));\r\n            szError = vips_error_buffer();\r\n            if (strlen(szError) > 0) {\r\n               printf(\"VImage::new_from_file: error text = %s\\n\", szError);\r\n            } else {\r\n               printf(\"VImage::new_from_file: no error info\\n\");\r\n            }\r\n         } catch (const VError & ex) {\r\n            printf(\"Caught exception %s opening %s\\n\", ex.what(),\r\n                  testFilePath.c_str());\r\n            break;\r\n         }\r\n         bool bTestSolution = false;\r\n         if (bTestSolution) {\r\n            double avg = testImage.avg();\r\n            szError = vips_error_buffer();\r\n            if (strlen(szError) > 0) {\r\n               printf(\"testImage.avg(): error text = %s\\n\", szError);\r\n               vips_error_clear();\r\n            } else {\r\n               printf(\"testImage.avg(): no error info\\n\");\r\n            }\r\n         }\r\n         try {\r\n            testImage.write_to_file(outFilePath.c_str());\r\n            szError = vips_error_buffer();\r\n            if (strlen(szError) > 0) {\r\n               printf(\"VImage::write_to_file: error text = %s\\n\", szError);\r\n            } else {\r\n               printf(\"VImage::write_to_file: no error info\\n\");\r\n            }\r\n         } catch (const VError & ex) {\r\n            printf(\"Caught exception %s writing %s\\n\", ex.what(),\r\n                  outFilePath.c_str());\r\n            break;\r\n         }\r\n      } while (false);\r\n   }\r\n   vips_shutdown();\r\n   printf(\"vipstestbadfiles_main ended\\n\");\r\n   return 0;\r\n}\r\n\r\n```\r\n\r\n![006e07875254_20160623015311](https://cloud.githubusercontent.com/assets/18052758/16337604/112c8680-3a17-11e6-87e0-5b5c65714e45.jpg)\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/jcupitt/libvips/issues/comments/236251512","html_url":"https://github.com/jcupitt/libvips/issues/474#issuecomment-236251512","issue_url":"https://api.github.com/repos/jcupitt/libvips/issues/474","id":236251512,"user":{"login":"DFKSingleton","id":18052758,"avatar_url":"https://avatars.githubusercontent.com/u/18052758?v=3","gravatar_id":"","url":"https://api.github.com/users/DFKSingleton","html_url":"https://github.com/DFKSingleton","followers_url":"https://api.github.com/users/DFKSingleton/followers","following_url":"https://api.github.com/users/DFKSingleton/following{/other_user}","gists_url":"https://api.github.com/users/DFKSingleton/gists{/gist_id}","starred_url":"https://api.github.com/users/DFKSingleton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DFKSingleton/subscriptions","organizations_url":"https://api.github.com/users/DFKSingleton/orgs","repos_url":"https://api.github.com/users/DFKSingleton/repos","events_url":"https://api.github.com/users/DFKSingleton/events{/privacy}","received_events_url":"https://api.github.com/users/DFKSingleton/received_events","type":"User","site_admin":false},"created_at":"2016-07-29T18:04:50Z","updated_at":"2016-07-29T18:04:50Z","body":"Hello John,\r\n\r\nThanks for the quick response. I have now run my test program with your tip (master) revision. The memory leaks are not there any more, so the problem is fixed. As far as I am concerned, this issue can be closed.\r\n\r\nThanks again\r\n\r\nDavid Singleton"}}
{"actor":{"display_login":"DFKSingleton"}}