Don't allow binary into the output stream!
This commit is contained in:
parent
338176b239
commit
43b06b6814
@ -90,13 +90,8 @@ if( EXIV2_BUILD_UNIT_TESTS )
|
||||
)
|
||||
endif()
|
||||
|
||||
# Run a reduced test suite on UNIX #902
|
||||
set (TEST alltest)
|
||||
if ( CMAKE_HOST_SOLARIS OR CMAKE_SYSTEM_NAME STREQUAL "NetBSD" OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" )
|
||||
set (TEST unixtest)
|
||||
endif()
|
||||
add_custom_target(version_test
|
||||
COMMAND env EXIV2_BINDIR="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" ./version_test.sh
|
||||
COMMAND env EXIV2_BINDIR="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" make version_test
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/test"
|
||||
)
|
||||
|
||||
@ -106,14 +101,14 @@ if( EXIV2_BUILD_SAMPLES )
|
||||
if( EXIV2_BUILD_UNIT_TESTS )
|
||||
add_custom_target(tests
|
||||
COMMAND env EXIV2_BINDIR="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" make unit_test
|
||||
COMMAND env EXIV2_BINDIR="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" make ${TEST}
|
||||
COMMAND env EXIV2_BINDIR="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" make bash_tests
|
||||
COMMAND env EXIV2_BINDIR="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" make python_tests
|
||||
COMMAND env EXIV2_BINDIR="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" make version_test
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/test"
|
||||
)
|
||||
else()
|
||||
add_custom_target(tests
|
||||
COMMAND env EXIV2_BINDIR="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" make ${TEST}
|
||||
COMMAND env EXIV2_BINDIR="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" make bash_tests
|
||||
COMMAND env EXIV2_BINDIR="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" make python_tests
|
||||
COMMAND env EXIV2_BINDIR="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" make version_test
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/test"
|
||||
@ -124,7 +119,7 @@ if( EXIV2_BUILD_SAMPLES )
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/test"
|
||||
)
|
||||
add_custom_target(bash_tests
|
||||
COMMAND env EXIV2_BINDIR="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" make ${TEST}
|
||||
COMMAND env EXIV2_BINDIR="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" make bash_tests
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/test"
|
||||
)
|
||||
add_subdirectory( samples )
|
||||
|
||||
@ -132,7 +132,7 @@ void print(const std::string& file)
|
||||
<< std::dec << std::setw(3)
|
||||
<< std::setfill(' ') << std::right
|
||||
<< i->count() << " "
|
||||
<< std::dec << i->value()
|
||||
<< std::dec << i->toString()
|
||||
<< "\n";
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ try {
|
||||
<< std::dec << std::setw(3)
|
||||
<< std::setfill(' ') << std::right
|
||||
<< i->count() << " "
|
||||
<< std::dec << i->value()
|
||||
<< std::dec << i->toString()
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
|
||||
@ -689,39 +689,13 @@ namespace Action {
|
||||
if (!first)
|
||||
std::cout << " ";
|
||||
first = false;
|
||||
if (md.size() > 128 && Params::instance().binary_ &&
|
||||
(md.typeId() == Exiv2::undefined || md.typeId() == Exiv2::unsignedByte ||
|
||||
md.typeId() == Exiv2::signedByte)) {
|
||||
std::cout << _("(Binary value suppressed)") << std::endl;
|
||||
return true;
|
||||
}
|
||||
bool done = false;
|
||||
// handle `comment` typeIDs
|
||||
// $ bin/taglist | grep '\tComment,' | cut -d, -f 5
|
||||
// Exif.Photo.UserComment
|
||||
// Exif.GPSInfo.GPSProcessingMethod
|
||||
// Exif.GPSInfo.GPSAreaInformation
|
||||
if( md.key() == "Exif.Photo.UserComment"
|
||||
|| md.key() == "Exif.GPSInfo.GPSProcessingMethod"
|
||||
|| md.key() == "Exif.GPSInfo.GPSAreaInformation"
|
||||
) {
|
||||
const Exiv2::CommentValue* pcv = dynamic_cast<const Exiv2::CommentValue*>(&md.value());
|
||||
if (pcv) {
|
||||
Exiv2::CommentValue::CharsetId csId = pcv->charsetId();
|
||||
if (csId != Exiv2::CommentValue::undefined) {
|
||||
std::cout << "charset=\"" << Exiv2::CommentValue::CharsetInfo::name(csId) << "\" ";
|
||||
}
|
||||
std::cout << pcv->comment(Params::instance().charset_.c_str());
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
if (!done) {
|
||||
// #1114 - show negative values for SByte
|
||||
if (md.typeId() != Exiv2::signedByte) {
|
||||
std::cout << std::dec << md.value();
|
||||
} else {
|
||||
int value = md.value().toLong();
|
||||
std::cout << std::dec << (value < 128 ? value : value - 256);
|
||||
// #1114 - show negative values for SByte
|
||||
if (md.typeId() != Exiv2::signedByte) {
|
||||
std::cout << std::dec << md.value();
|
||||
} else {
|
||||
for ( int c = 0 ; c < md.value().count() ; c++ ) {
|
||||
int value = md.value().toLong(c);
|
||||
std::cout << (c?" ":"") << std::dec << (value < 128 ? value : value - 256);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -729,35 +703,12 @@ namespace Action {
|
||||
if (!first)
|
||||
std::cout << " ";
|
||||
first = false;
|
||||
if (Params::instance().binary_ &&
|
||||
(md.typeId() == Exiv2::undefined || md.typeId() == Exiv2::unsignedByte ||
|
||||
md.typeId() == Exiv2::signedByte) &&
|
||||
md.size() > 128) {
|
||||
std::cout << _("(Binary value suppressed)") << std::endl;
|
||||
return true;
|
||||
}
|
||||
bool done = false;
|
||||
if (0 == strcmp(md.key().c_str(), "Exif.Photo.UserComment")) {
|
||||
const Exiv2::CommentValue* pcv = dynamic_cast<const Exiv2::CommentValue*>(&md.value());
|
||||
if (pcv) {
|
||||
std::cout << pcv->comment(Params::instance().charset_.c_str());
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
if (!done)
|
||||
std::cout << std::dec << md.print(&pImage->exifData());
|
||||
std::cout << std::dec << md.print(&pImage->exifData());
|
||||
}
|
||||
if (Params::instance().printItems_ & Params::prHex) {
|
||||
if (!first)
|
||||
std::cout << std::endl;
|
||||
first = false;
|
||||
if (Params::instance().binary_ &&
|
||||
(md.typeId() == Exiv2::undefined || md.typeId() == Exiv2::unsignedByte ||
|
||||
md.typeId() == Exiv2::signedByte) &&
|
||||
md.size() > 128) {
|
||||
std::cout << _("(Binary value suppressed)") << std::endl;
|
||||
return true;
|
||||
}
|
||||
Exiv2::DataBuf buf(md.size());
|
||||
md.copy(buf.pData_, pImage->byteOrder());
|
||||
Exiv2::hexdump(std::cout, buf.pData_, buf.size_);
|
||||
|
||||
17
src/exif.cpp
17
src/exif.cpp
@ -219,10 +219,19 @@ namespace Exiv2 {
|
||||
std::ostream& Exifdatum::write(std::ostream& os, const ExifData* pMetadata) const
|
||||
{
|
||||
if (value().count() == 0) return os;
|
||||
PrintFct fct = printValue;
|
||||
const TagInfo* ti = Internal::tagInfo(tag(), static_cast<IfdId>(ifdId()));
|
||||
if (ti != 0) fct = ti->printFct_;
|
||||
return fct(os, value(), pMetadata);
|
||||
|
||||
PrintFct fct = printValue;
|
||||
const TagInfo* ti = Internal::tagInfo(tag(), static_cast<IfdId>(ifdId()));
|
||||
// be careful with comments (User.Photo.UserComment, GPSAreaInfo etc).
|
||||
if ( ti ) {
|
||||
fct = ti->printFct_;
|
||||
if ( ti->typeId_ == comment ) {
|
||||
os << value().toString();
|
||||
fct=NULL;
|
||||
}
|
||||
}
|
||||
if ( fct ) fct(os, value(), pMetadata);
|
||||
return os;
|
||||
}
|
||||
|
||||
const Value& Exifdatum::value() const
|
||||
|
||||
@ -555,6 +555,16 @@ namespace Exiv2 {
|
||||
return os << comment();
|
||||
}
|
||||
|
||||
static bool isBinary(const std::string& s)
|
||||
{
|
||||
bool result = false ;
|
||||
size_t i = 0;
|
||||
while ( !result && i < s.length() ) {
|
||||
result = s[i++] < 32 || s[i] > 127 ;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string CommentValue::comment(const char* encoding) const
|
||||
{
|
||||
std::string c;
|
||||
@ -565,6 +575,10 @@ namespace Exiv2 {
|
||||
if (charsetId() == unicode) {
|
||||
const char* from = encoding == 0 || *encoding == '\0' ? detectCharset(c) : encoding;
|
||||
convertStringCharset(c, from, "UTF-8");
|
||||
} else {
|
||||
if ( isBinary(c) ) {
|
||||
c = "binary comment" ;
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
@ -1191,7 +1205,7 @@ namespace Exiv2 {
|
||||
time_.hour, time_.minute, time_.second,
|
||||
plusMinus, abs(time_.tzHour), abs(time_.tzMinute));
|
||||
|
||||
enforce(wrote == 11, Exiv2::kerUnsupportedTimeFormat);
|
||||
// enforce(wrote == 11, Exiv2::kerUnsupportedTimeFormat);
|
||||
std::memcpy(buf, temp, wrote);
|
||||
return wrote;
|
||||
}
|
||||
|
||||
@ -72,29 +72,24 @@ SVN = svn://dev.exiv2.org/svn/testdata/trunk
|
||||
|
||||
##
|
||||
# Add test drivers to this list
|
||||
TESTS1 = addmoddel.sh \
|
||||
TESTS = addmoddel.sh \
|
||||
conversions.sh \
|
||||
exifdata-test.sh \
|
||||
exiv2-test.sh \
|
||||
geotag-test.sh \
|
||||
icc-test.sh \
|
||||
iso65k-test.sh \
|
||||
modify-test.sh \
|
||||
path-test.sh \
|
||||
stringto-test.sh \
|
||||
webp-test.sh \
|
||||
write2-test.sh \
|
||||
|
||||
# the following tests are broken on UNIX
|
||||
# You can manually run all the tests: `cd <exiv2dir>/test ; env EXIV2_BINDIR=$PWD/../build/bin make test`
|
||||
# You can manually run a single test: `cd <exiv2dir>/test ; env EXIV2_BINDIR=$PWD/../build/bin ./iotest.sh`
|
||||
# Or: make iotest
|
||||
TESTS2 = exifdata-test.sh \
|
||||
exiv2-test.sh \
|
||||
imagetest.sh \
|
||||
iotest.sh \
|
||||
iptctest.sh \
|
||||
iso65k-test.sh \
|
||||
modify-test.sh \
|
||||
path-test.sh \
|
||||
preview-test.sh \
|
||||
stringto-test.sh \
|
||||
tiff-test.sh \
|
||||
webp-test.sh \
|
||||
write-test.sh \
|
||||
write2-test.sh \
|
||||
xmpparser-test.sh
|
||||
|
||||
# video tests
|
||||
@ -136,30 +131,29 @@ xmpparser-test:
|
||||
|
||||
version_test \
|
||||
unit_test :
|
||||
@echo
|
||||
@echo ---- Running $@ ----
|
||||
@echo
|
||||
-@./$@.sh
|
||||
|
||||
bash_tests:
|
||||
-@if [ -e $$EXIV2_BINDIR/../Makefile ]; then \
|
||||
-@./$@.sh ; \
|
||||
else \
|
||||
make alltest ; \
|
||||
fi
|
||||
|
||||
tests:
|
||||
-@if [ -e $$EXIV2_BINDIR/../Makefile ]; then \
|
||||
-@./$@.sh ; \
|
||||
else \
|
||||
make unit_test ; make alltest ; make python_tests ; make version_test ; \
|
||||
make unit_test ; \
|
||||
make bash_tests ; \
|
||||
make python_tests ; \
|
||||
make version_test ; \
|
||||
fi
|
||||
|
||||
|
||||
alltest:
|
||||
bash_tests:
|
||||
@echo
|
||||
@echo ---- Running bash tests: ALL ----
|
||||
@echo ---- Running bash_tests ----
|
||||
@echo
|
||||
mkdir -p tmp
|
||||
@mkdir -p tmp
|
||||
@rm -rf tmp/test-failed
|
||||
@list='$(TESTS1) $(TESTS2)'; for p in $$list; do \
|
||||
@list='$(TESTS)'; for p in $$list; do \
|
||||
echo Running $$p ...; \
|
||||
./$$p; \
|
||||
rc=$$?; \
|
||||
@ -168,25 +162,13 @@ alltest:
|
||||
done
|
||||
@if [ -e tmp/test-failed ]; then echo ; echo '***' FAILED ; cat tmp/test-failed ; echo '***' ; fi
|
||||
|
||||
unixtest:
|
||||
@echo
|
||||
@echo ---- Running bash tests: UNIX subset ----
|
||||
@echo
|
||||
mkdir -p tmp
|
||||
@rm -rf tmp/test-failed
|
||||
@list='$(TESTS1)'; for p in $$list; do \
|
||||
echo Running $$p ...; \
|
||||
./$$p; \
|
||||
rc=$$?; \
|
||||
if [ $$rc -ne 0 ]; then echo '***' ; echo '***' $$p result = $$rc ; echo '***' ; fi ; \
|
||||
if [ $$rc -ne 0 ]; then echo '***' $$p result = $$rc >> tmp/test-failed ; fi ; \
|
||||
done
|
||||
@if [ -e tmp/test-failed ]; then echo '***' FAILED ; cat tmp/test-failed ; echo '***' ; fi
|
||||
|
||||
python_tests:
|
||||
@echo
|
||||
@echo ---- Running python_tests ----
|
||||
@echo
|
||||
-( cd ../tests ; if [ ! -z $$VERBOSE ]; then verbose=--verbose ;fi ; python3 runner.py $$verbose )
|
||||
|
||||
|
||||
testv:
|
||||
@for t in /video ; do \
|
||||
if [ ! -e data/$$t ]; then \
|
||||
|
||||
@ -267,7 +267,7 @@ Exif.Canon.FileNumber 0x0008 Makernote Long 1
|
||||
Exif.Canon.OwnerName 0x0009 Makernote Ascii 32 Andreas Huggel
|
||||
Exif.Canon.ModelID 0x0010 Makernote Long 1 17891328
|
||||
Exif.Canon.CameraInfo 0x000d Makernote Short 21 42 3 32769 378 32769 0 0 0 259 2 0 10 0 0 0 57 198 5 0 0 0
|
||||
Exif.Photo.UserComment 0x9286 Exif Undefined 264 | ||||