fix895-ICCProfile-FalseWarning

v0.27.3
clanmills 6 years ago
parent 5a3afa9cbe
commit ab0b97c729

@ -1430,12 +1430,12 @@ namespace Exiv2 {
void XPathIo::ReadStdin() { void XPathIo::ReadStdin() {
if (isatty(fileno(stdin))) if (isatty(fileno(stdin)))
throw Error(kerInvalidIccProfile); throw Error(kerInputDataReadFailed);
#ifdef _O_BINARY #ifdef _O_BINARY
// convert stdin to binary // convert stdin to binary
if (_setmode(_fileno(stdin), _O_BINARY) == -1) if (_setmode(_fileno(stdin), _O_BINARY) == -1)
throw Error(kerInvalidXMP); throw Error(kerInputDataReadFailed);
#endif #endif
char readBuf[100*1024]; char readBuf[100*1024];
@ -1511,16 +1511,16 @@ namespace Exiv2 {
std::stringstream ss; std::stringstream ss;
ss << timestamp << XPathIo::TEMP_FILE_EXT; ss << timestamp << XPathIo::TEMP_FILE_EXT;
std::string path = ss.str(); std::string path = ss.str();
std::ofstream fs(path.c_str(), std::ios::out | std::ios::binary | std::ios::trunc);
if (prot == pStdin) { if (prot == pStdin) {
if (isatty(fileno(stdin))) if (isatty(fileno(stdin)))
throw Error(kerInvalidIccProfile); throw Error(kerInputDataReadFailed);
#if defined(_MSC_VER) || defined(__MINGW__) #if defined(_MSC_VER) || defined(__MINGW__)
// convert stdin to binary // convert stdin to binary
if (_setmode(_fileno(stdin), _O_BINARY) == -1) if (_setmode(_fileno(stdin), _O_BINARY) == -1)
throw Error(kerInvalidXMP); throw Error(kerInputDataReadFailed);
#endif #endif
std::ofstream fs(path.c_str(), std::ios::out | std::ios::binary | std::ios::trunc);
// read stdin and write to the temp file. // read stdin and write to the temp file.
char readBuf[100*1024]; char readBuf[100*1024];
std::streamsize readBufSize = 0; std::streamsize readBufSize = 0;
@ -1531,23 +1531,29 @@ namespace Exiv2 {
fs.write (readBuf, readBufSize); fs.write (readBuf, readBufSize);
} }
} while(readBufSize); } while(readBufSize);
fs.close();
} else if (prot == pDataUri) { } else if (prot == pDataUri) {
std::ofstream fs(path.c_str(), std::ios::out | std::ios::binary | std::ios::trunc);
// read data uri and write to the temp file. // read data uri and write to the temp file.
size_t base64Pos = orgPath.find("base64,"); size_t base64Pos = orgPath.find("base64,");
if (base64Pos == std::string::npos) if (base64Pos == std::string::npos) {
fs.close();
throw Error(kerErrorMessage, "No base64 data"); throw Error(kerErrorMessage, "No base64 data");
}
std::string data = orgPath.substr(base64Pos+7); std::string data = orgPath.substr(base64Pos+7);
char* decodeData = new char[data.length()]; char* decodeData = new char[data.length()];
long size = base64decode(data.c_str(), decodeData, data.length()); long size = base64decode(data.c_str(), decodeData, data.length());
if (size > 0) if (size > 0) {
fs.write(decodeData, size); fs.write(decodeData, size);
else fs.close();
} else {
fs.close();
throw Error(kerErrorMessage, "Unable to decode base 64."); throw Error(kerErrorMessage, "Unable to decode base 64.");
}
delete[] decodeData; delete[] decodeData;
} }
fs.close();
return path; return path;
} }

@ -259,18 +259,21 @@ namespace Exiv2 {
struct { struct {
std::string name ; std::string name ;
Protocol prot ; Protocol prot ;
bool url ; // path.size() > name.size()
} prots[] = } prots[] =
{ { "http://" ,pHttp } { { "http://" ,pHttp , true }
, { "https://" ,pHttps } , { "https://" ,pHttps , true }
, { "ftp://" ,pFtp } , { "ftp://" ,pFtp , true }
, { "sftp://" ,pSftp } , { "sftp://" ,pSftp , true }
, { "ssh://" ,pSsh } , { "ssh://" ,pSsh , true }
, { "file://" ,pFileUri } , { "file://" ,pFileUri , true }
, { "data://" ,pDataUri } , { "data://" ,pDataUri , true }
, { "-" ,pStdin } , { "-" ,pStdin , false }
}; };
for ( size_t i = 0 ; result == pFile && i < sizeof(prots)/sizeof(prots[0]) ; i ++ ) for ( size_t i = 0 ; result == pFile && i < sizeof(prots)/sizeof(prots[0]) ; i ++ )
if ( path.find(prots[i].name) == 0 ) if ( path.find(prots[i].name) == 0 )
// URL's require data. Stdin == "-" and no further data
if ( prots[i].url ? path.size() > prots[i].name.size() : path.size() == prots[i].name.size() )
result = prots[i].prot; result = prots[i].prot;
return result; return result;
@ -281,18 +284,21 @@ namespace Exiv2 {
struct { struct {
std::wstring wname ; std::wstring wname ;
Protocol prot ; Protocol prot ;
bool url ; // path.size() > name.size()
} prots[] = } prots[] =
{ { L"http://" ,pHttp } { { L"http://" ,pHttp , true }
, { L"https://" ,pHttps } , { L"https://" ,pHttps , true }
, { L"ftp://" ,pFtp } , { L"ftp://" ,pFtp , true }
, { L"sftp://" ,pSftp } , { L"sftp://" ,pSftp , true }
, { L"ssh://" ,pSsh } , { L"ssh://" ,pSsh , true }
, { L"file://" ,pFileUri } , { L"file://" ,pFileUri , true }
, { L"data://" ,pDataUri } , { L"data://" ,pDataUri , true }
, { L"-" ,pStdin } , { L"-" ,pStdin , false }
}; };
for ( size_t i = 0 ; result == pFile && i < sizeof(prots)/sizeof(prots[0]) ; i ++ ) for ( size_t i = 0 ; result == pFile && i < sizeof(prots)/sizeof(prots[0]) ; i ++ )
if ( wpath.find(prots[i].wname) == 0 ) if ( path.find(prots[i].name) == 0 )
// URL's require data. Stdin == "-" and no further data
if ( prots[i].url ? path.size() > prots[i].name.size() : path.size() == prots[i].name.size() )
result = prots[i].prot; result = prots[i].prot;
return result; return result;

Loading…
Cancel
Save