From 6cd9263fa7b74ec2e57a3e191d01a8189715a09c Mon Sep 17 00:00:00 2001 From: postscript-dev <43813-postscript-dev@users.noreply.gitlab.gnome.org> Date: Sat, 6 Mar 2021 18:59:31 +0000 Subject: [PATCH 1/5] Fix langAltValue::read() parsing + Fix segmentation faults in langAlt parse + Fix mismatched quotation marks and incorrect values + Add Python testing + Some tests commented out as quotation marks are filtered, preventing them from running. Closes #1481. --- include/exiv2/error.hpp | 1 + src/error.cpp | 2 + src/value.cpp | 27 +++- tests/bugfixes/github/test_issue_1481.py | 160 +++++++++++++++++++++++ tests/suite.conf | 2 + 5 files changed, 189 insertions(+), 3 deletions(-) create mode 100644 tests/bugfixes/github/test_issue_1481.py diff --git a/include/exiv2/error.hpp b/include/exiv2/error.hpp index 1787f10ca3..942a4cd59b 100644 --- a/include/exiv2/error.hpp +++ b/include/exiv2/error.hpp @@ -249,6 +249,7 @@ namespace Exiv2 { kerInvalidXMP, kerTiffDirectoryTooLarge, kerInvalidTypeValue, + kerInvalidLangAltValue, kerInvalidMalloc, kerCorruptedMetadata, kerArithmeticOverflow, diff --git a/src/error.cpp b/src/error.cpp index 05d83de8a1..f68cc64ee5 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -158,6 +158,8 @@ namespace { N_("tiff directory length is too large") }, { Exiv2::kerInvalidTypeValue, N_("invalid type in tiff structure") }, + { Exiv2::kerInvalidLangAltValue, + N_("Invalid LangAlt value `%1'") }, // %1=value { Exiv2::kerInvalidMalloc, N_("invalid memory allocation request") }, { Exiv2::kerCorruptedMetadata, diff --git a/src/value.cpp b/src/value.cpp index b96f7de350..8e50a392c4 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -856,18 +856,39 @@ namespace Exiv2 { } int LangAltValue::read(const std::string& buf) - { + { std::string b = buf; std::string lang = "x-default"; if (buf.length() > 5 && buf.substr(0, 5) == "lang=") { + const char* ALPLHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + const char* ALPLHA_NUM = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + std::string::size_type pos = buf.find_first_of(' '); lang = buf.substr(5, pos-5); // Strip quotes (so you can also specify the language without quotes) - if (lang[0] == '"') lang = lang.substr(1); - if (lang[lang.length()-1] == '"') lang = lang.substr(0, lang.length()-1); + if (lang[0] == '"') { + lang = lang.substr(1); + + if (lang == "" || lang.find('"') != lang.length()-1) + throw Error(kerInvalidLangAltValue, buf); // *** + + lang = lang.substr(0, lang.length()-1); + } + + if (lang == "") throw Error(kerInvalidLangAltValue, buf); // *** + + // Check language is in the correct format (see https://www.ietf.org/rfc/rfc3066.txt) + std::string::size_type charPos = lang.find_first_not_of(ALPLHA); + if (charPos != std::string::npos) { + if (lang[charPos] != '-' || lang.find_first_not_of(ALPLHA_NUM, charPos+1) != std::string::npos) + throw Error(kerInvalidLangAltValue, buf); + } + b.clear(); if (pos != std::string::npos) b = buf.substr(pos+1); } + + value_[lang] = b; return 0; } diff --git a/tests/bugfixes/github/test_issue_1481.py b/tests/bugfixes/github/test_issue_1481.py new file mode 100644 index 0000000000..fe94134630 --- /dev/null +++ b/tests/bugfixes/github/test_issue_1481.py @@ -0,0 +1,160 @@ +# -*- coding: utf-8 -*- + +import system_tests + +@system_tests.CopyFiles("$data_path/exiv2-empty.jpg") +class CheckXmpLangAltValues(metaclass=system_tests.CaseMeta): + + url = "https://github.com/Exiv2/exiv2/issues/1481" + +# Python unittest is filtering out empty pairs of "" and flags up an error if +# a mismatched number of quotes is used inside the commands[] (see +# https://docs.python.org/3/library/shlex.html#parsing-rules). +# +# This means that some of the tests in the github issue cannot be run. + + langAltValue = [ + # 1. No language value + """lang= test1-1""", + """lang=\" test1-2""", + + # 2. Empty language value + """lang=\"\" test2""", + + # 3. Mismatched and/or incorrect positioning of quotation marks + """lang=\"\"test3-1""", + """lang=\"test3-2""", + """lang=\"en-UK test3-3""", + """lang=en-US\" test3-4""", + """lang=test3-5\"""", + """lang=test3-6\"\"""", + + # 4. Invalid characters in language part + """lang=en-UK- test4-1""", + """lang=en=UK test4-2""", + ] + + filename = system_tests.path("$data_path/exiv2-empty_copy.jpg") + + commands = [ + # 1. No language value + """$exiv2 -M"set Xmp.dc.title """ + langAltValue[0] + """" $filename""", +# """$exiv2 -M"set Xmp.dc.title """ + langAltValue[1] + """" $filename""", + """$exiv2 -px $filename""", + + # 2. Empty language value +# """$exiv2 -M"set Xmp.dc.title """ + langAltValue[2] + """" $filename""", +# """$exiv2 -px $filename""", + + # 3. Mismatched and/or incorrect positioning of quotation marks +# """$exiv2 -M"set Xmp.dc.title """ + langAltValue[3] + """" $filename""", +# """$exiv2 -M"set Xmp.dc.title """ + langAltValue[4] + """" $filename""", +# """$exiv2 -M"set Xmp.dc.title """ + langAltValue[5] + """" $filename""", +# """$exiv2 -M"set Xmp.dc.title """ + langAltValue[6] + """" $filename""", +# """$exiv2 -M"set Xmp.dc.title """ + langAltValue[7] + """" $filename""", +# """$exiv2 -M"set Xmp.dc.title """ + langAltValue[8] + """" $filename""", +# """$exiv2 -px $filename""", + + # 4. Invalid characters in language part + """$exiv2 -M"set Xmp.dc.title """ + langAltValue[9] + """" $filename""", + """$exiv2 -M"set Xmp.dc.title """ + langAltValue[10] + """" $filename""", + """$exiv2 -px $filename""" + ] + + stdout = [ + # 1. No language value + "", +# "", + "", + + # 2. Empty language value +# "", +# "", + + # 3. Mismatched and/or incorrect positioning of quotation marks +# "", +# "", +# "", +# "", +# "", +# "", +# "", + + # 4. Invalid characters in language part + "", + "", + "" + ] + + stderr = [ + # 1. No language value + """$exiv2_modify_exception_message $filename: +$kerInvalidLangAltValue `""" + langAltValue[0] + """' +""", +# """$exiv2_modify_exception_message $filename: +# $kerInvalidLangAltValue `""" + langAltValue[1] + """' +# """, + "", + + # 2. Empty language value +# """$exiv2_modify_exception_message $filename: +# $kerInvalidLangAltValue `""" + langAltValue[2] + """' +# """, +# "", + + # 3. Mismatched and/or incorrect positioning of quotation marks +# """$exiv2_modify_exception_message $filename: +# $kerInvalidLangAltValue `""" + langAltValue[3] + """' +# """, +# """$exiv2_modify_exception_message $filename: +# $kerInvalidLangAltValue `""" + langAltValue[4] + """' +# """, +# """$exiv2_modify_exception_message $filename: +# $kerInvalidLangAltValue `""" + langAltValue[5] + """' +# """, +# """$exiv2_modify_exception_message $filename: +# $kerInvalidLangAltValue `""" + langAltValue[6] + """' +# """, +# """$exiv2_modify_exception_message $filename: +# $kerInvalidLangAltValue `""" + langAltValue[7] + """' +# """, +# """$exiv2_modify_exception_message $filename: +# $kerInvalidLangAltValue `""" + langAltValue[8] + """' +# """, +# "", + + # 4. Invalid characters in language part + """$exiv2_modify_exception_message $filename: +$kerInvalidLangAltValue `""" + langAltValue[9] + """' +""", + """$exiv2_modify_exception_message $filename: +$kerInvalidLangAltValue `""" + langAltValue[10] + """' +""", + "" + ] + + retval = [ + # 1. No language value + 1, +# 1, + 0, + + # 2. Empty language value +# 1, +# 0, + + # 3. Mismatched and/or incorrect positioning of quotation marks +# 1, +# 1, +# 1, +# 1, +# 1, +# 1, +# 0, + + # 4. Invalid characters in language part + 1, + 1, + 0 + ] + diff --git a/tests/suite.conf b/tests/suite.conf index e5c48c21fb..4af1af1b46 100644 --- a/tests/suite.conf +++ b/tests/suite.conf @@ -42,8 +42,10 @@ kerInvalidTypeValue: invalid type in tiff structure kerNotAJpeg : This does not look like a JPEG image kerNoImageInInputData: Input data does not contain a valid image kerFileContainsUnknownImageType: The file contains data of an unknown image type +kerInvalidLangAltValue: Invalid LangAlt value addition_overflow_message: Overflow in addition exiv2_exception_message: Exiv2 exception in print action for file +exiv2_modify_exception_message: Exiv2 exception in modify action for file exiv2_overflow_exception_message: std::overflow_error exception in print action for file exception_in_extract: Exiv2 exception in extract action for file uncaught_exception: Uncaught exception: From 282d1d699555ec979195ddf286214a2739b9fbdc Mon Sep 17 00:00:00 2001 From: postscript-dev <43813-postscript-dev@users.noreply.gitlab.gnome.org> Date: Mon, 8 Mar 2021 10:27:11 +0000 Subject: [PATCH 2/5] Add static to LangAltValue::read() const values --- src/value.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/value.cpp b/src/value.cpp index 8e50a392c4..180bbecdd8 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -860,8 +860,8 @@ namespace Exiv2 { std::string b = buf; std::string lang = "x-default"; if (buf.length() > 5 && buf.substr(0, 5) == "lang=") { - const char* ALPLHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - const char* ALPLHA_NUM = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + static const char* ALPLHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + static const char* ALPLHA_NUM = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; std::string::size_type pos = buf.find_first_of(' '); lang = buf.substr(5, pos-5); From 207a0d65c9451733bf4e98cf2e2256c559d25eaf Mon Sep 17 00:00:00 2001 From: postscript-dev <43813-postscript-dev@users.noreply.gitlab.gnome.org> Date: Tue, 9 Mar 2021 11:58:55 +0000 Subject: [PATCH 3/5] Change LangAltValue::read() tests to unitTests Removed previous Python tests. --- tests/bugfixes/github/test_issue_1481.py | 160 ------------------ tests/suite.conf | 2 - unitTests/CMakeLists.txt | 1 + unitTests/test_LangAltValueRead.cpp | 199 +++++++++++++++++++++++ 4 files changed, 200 insertions(+), 162 deletions(-) delete mode 100644 tests/bugfixes/github/test_issue_1481.py create mode 100644 unitTests/test_LangAltValueRead.cpp diff --git a/tests/bugfixes/github/test_issue_1481.py b/tests/bugfixes/github/test_issue_1481.py deleted file mode 100644 index fe94134630..0000000000 --- a/tests/bugfixes/github/test_issue_1481.py +++ /dev/null @@ -1,160 +0,0 @@ -# -*- coding: utf-8 -*- - -import system_tests - -@system_tests.CopyFiles("$data_path/exiv2-empty.jpg") -class CheckXmpLangAltValues(metaclass=system_tests.CaseMeta): - - url = "https://github.com/Exiv2/exiv2/issues/1481" - -# Python unittest is filtering out empty pairs of "" and flags up an error if -# a mismatched number of quotes is used inside the commands[] (see -# https://docs.python.org/3/library/shlex.html#parsing-rules). -# -# This means that some of the tests in the github issue cannot be run. - - langAltValue = [ - # 1. No language value - """lang= test1-1""", - """lang=\" test1-2""", - - # 2. Empty language value - """lang=\"\" test2""", - - # 3. Mismatched and/or incorrect positioning of quotation marks - """lang=\"\"test3-1""", - """lang=\"test3-2""", - """lang=\"en-UK test3-3""", - """lang=en-US\" test3-4""", - """lang=test3-5\"""", - """lang=test3-6\"\"""", - - # 4. Invalid characters in language part - """lang=en-UK- test4-1""", - """lang=en=UK test4-2""", - ] - - filename = system_tests.path("$data_path/exiv2-empty_copy.jpg") - - commands = [ - # 1. No language value - """$exiv2 -M"set Xmp.dc.title """ + langAltValue[0] + """" $filename""", -# """$exiv2 -M"set Xmp.dc.title """ + langAltValue[1] + """" $filename""", - """$exiv2 -px $filename""", - - # 2. Empty language value -# """$exiv2 -M"set Xmp.dc.title """ + langAltValue[2] + """" $filename""", -# """$exiv2 -px $filename""", - - # 3. Mismatched and/or incorrect positioning of quotation marks -# """$exiv2 -M"set Xmp.dc.title """ + langAltValue[3] + """" $filename""", -# """$exiv2 -M"set Xmp.dc.title """ + langAltValue[4] + """" $filename""", -# """$exiv2 -M"set Xmp.dc.title """ + langAltValue[5] + """" $filename""", -# """$exiv2 -M"set Xmp.dc.title """ + langAltValue[6] + """" $filename""", -# """$exiv2 -M"set Xmp.dc.title """ + langAltValue[7] + """" $filename""", -# """$exiv2 -M"set Xmp.dc.title """ + langAltValue[8] + """" $filename""", -# """$exiv2 -px $filename""", - - # 4. Invalid characters in language part - """$exiv2 -M"set Xmp.dc.title """ + langAltValue[9] + """" $filename""", - """$exiv2 -M"set Xmp.dc.title """ + langAltValue[10] + """" $filename""", - """$exiv2 -px $filename""" - ] - - stdout = [ - # 1. No language value - "", -# "", - "", - - # 2. Empty language value -# "", -# "", - - # 3. Mismatched and/or incorrect positioning of quotation marks -# "", -# "", -# "", -# "", -# "", -# "", -# "", - - # 4. Invalid characters in language part - "", - "", - "" - ] - - stderr = [ - # 1. No language value - """$exiv2_modify_exception_message $filename: -$kerInvalidLangAltValue `""" + langAltValue[0] + """' -""", -# """$exiv2_modify_exception_message $filename: -# $kerInvalidLangAltValue `""" + langAltValue[1] + """' -# """, - "", - - # 2. Empty language value -# """$exiv2_modify_exception_message $filename: -# $kerInvalidLangAltValue `""" + langAltValue[2] + """' -# """, -# "", - - # 3. Mismatched and/or incorrect positioning of quotation marks -# """$exiv2_modify_exception_message $filename: -# $kerInvalidLangAltValue `""" + langAltValue[3] + """' -# """, -# """$exiv2_modify_exception_message $filename: -# $kerInvalidLangAltValue `""" + langAltValue[4] + """' -# """, -# """$exiv2_modify_exception_message $filename: -# $kerInvalidLangAltValue `""" + langAltValue[5] + """' -# """, -# """$exiv2_modify_exception_message $filename: -# $kerInvalidLangAltValue `""" + langAltValue[6] + """' -# """, -# """$exiv2_modify_exception_message $filename: -# $kerInvalidLangAltValue `""" + langAltValue[7] + """' -# """, -# """$exiv2_modify_exception_message $filename: -# $kerInvalidLangAltValue `""" + langAltValue[8] + """' -# """, -# "", - - # 4. Invalid characters in language part - """$exiv2_modify_exception_message $filename: -$kerInvalidLangAltValue `""" + langAltValue[9] + """' -""", - """$exiv2_modify_exception_message $filename: -$kerInvalidLangAltValue `""" + langAltValue[10] + """' -""", - "" - ] - - retval = [ - # 1. No language value - 1, -# 1, - 0, - - # 2. Empty language value -# 1, -# 0, - - # 3. Mismatched and/or incorrect positioning of quotation marks -# 1, -# 1, -# 1, -# 1, -# 1, -# 1, -# 0, - - # 4. Invalid characters in language part - 1, - 1, - 0 - ] - diff --git a/tests/suite.conf b/tests/suite.conf index 4af1af1b46..e5c48c21fb 100644 --- a/tests/suite.conf +++ b/tests/suite.conf @@ -42,10 +42,8 @@ kerInvalidTypeValue: invalid type in tiff structure kerNotAJpeg : This does not look like a JPEG image kerNoImageInInputData: Input data does not contain a valid image kerFileContainsUnknownImageType: The file contains data of an unknown image type -kerInvalidLangAltValue: Invalid LangAlt value addition_overflow_message: Overflow in addition exiv2_exception_message: Exiv2 exception in print action for file -exiv2_modify_exception_message: Exiv2 exception in modify action for file exiv2_overflow_exception_message: std::overflow_error exception in print action for file exception_in_extract: Exiv2 exception in extract action for file uncaught_exception: Uncaught exception: diff --git a/unitTests/CMakeLists.txt b/unitTests/CMakeLists.txt index 5c74100b6b..331c1278bb 100644 --- a/unitTests/CMakeLists.txt +++ b/unitTests/CMakeLists.txt @@ -33,6 +33,7 @@ add_executable(unit_tests test_slice.cpp test_tiffheader.cpp test_types.cpp + test_LangAltValueRead.cpp gtestwrapper.h ${unit_tests_exiv2lib_SOURCES} ) diff --git a/unitTests/test_LangAltValueRead.cpp b/unitTests/test_LangAltValueRead.cpp new file mode 100644 index 0000000000..4ac8e2b75f --- /dev/null +++ b/unitTests/test_LangAltValueRead.cpp @@ -0,0 +1,199 @@ +#include + +#include "gtestwrapper.h" + +using namespace Exiv2; + +// The tests corrispond to those in issue https://github.com/Exiv2/exiv2/issues/1481 + + +// 1. No language value +TEST(LangAltValueReadTest, noLangugeValBeforeSpace) +{ + XmpParser::initialize(); + ::atexit(XmpParser::terminate); + + Exiv2::XmpData xmpData; + try { + xmpData["Xmp.dc.title"] = "lang= test1-1"; + } + catch (AnyError& e) { + ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue); + } + catch (...) { + ASSERT_TRUE(false); + } +} + +TEST(LangAltValueReadTest, quoteThenNoLangugeValBeforeSpace) +{ + XmpParser::initialize(); + ::atexit(XmpParser::terminate); + + Exiv2::XmpData xmpData; + try { + xmpData["Xmp.dc.title"] = "lang=\" test1-2"; + } + catch (AnyError& e) { + ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue); + } + catch (...) { + ASSERT_TRUE(false); + } +} + +// 2. Empty language value +TEST(LangAltValueReadTest, emptyDoubleQuotesLanguageValBeforeSpace) +{ + XmpParser::initialize(); + ::atexit(XmpParser::terminate); + + Exiv2::XmpData xmpData; + try { + xmpData["Xmp.dc.title"] = "lang=\"\" test2"; + } + catch (AnyError& e) { + ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue); + } + catch (...) { + ASSERT_TRUE(false); + } +} + +// 3. Mismatched and/or incorrect positioning of quotation marks +TEST(LangAltValueReadTest, emptyDoubleQuotesLanguageValNoSpace) +{ + XmpParser::initialize(); + ::atexit(XmpParser::terminate); + + Exiv2::XmpData xmpData; + try { + xmpData["Xmp.dc.title"] = "lang=\"\"test3-1"; + } + catch (AnyError& e) { + ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue); + } + catch (...) { + ASSERT_TRUE(false); + } +} + +TEST(LangAltValueReadTest, oneDoubleQuotesLanguageValNoSpace) +{ + XmpParser::initialize(); + ::atexit(XmpParser::terminate); + + Exiv2::XmpData xmpData; + try { + xmpData["Xmp.dc.title"] = "lang=\"test3-2"; + } + catch (AnyError& e) { + ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue); + } + catch (...) { + ASSERT_TRUE(false); + } +} + +TEST(LangAltValueReadTest, oneDoubleQuotesLanguageValBeforeSpace) +{ + XmpParser::initialize(); + ::atexit(XmpParser::terminate); + + Exiv2::XmpData xmpData; + try { + xmpData["Xmp.dc.title"] = "lang=\"en-UK test3-3"; + } + catch (AnyError& e) { + ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue); + } + catch (...) { + ASSERT_TRUE(false); + } +} + +TEST(LangAltValueReadTest, languageValOneDoubleQuotesBeforeSpace) +{ + XmpParser::initialize(); + ::atexit(XmpParser::terminate); + + Exiv2::XmpData xmpData; + try { + xmpData["Xmp.dc.title"] = "lang=en-US\" test3-4"; + } + catch (AnyError& e) { + ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue); + } + catch (...) { + ASSERT_TRUE(false); + } +} + +TEST(LangAltValueReadTest, languageValOneDoubleQuotesNoSpace) +{ + XmpParser::initialize(); + ::atexit(XmpParser::terminate); + + Exiv2::XmpData xmpData; + try { + xmpData["Xmp.dc.title"] = "lang=test3-5\""; + } + catch (AnyError& e) { + ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue); + } + catch (...) { + ASSERT_TRUE(false); + } +} + +TEST(LangAltValueReadTest, languageValTwoDoubleQuotesNoSpace) +{ + XmpParser::initialize(); + ::atexit(XmpParser::terminate); + + Exiv2::XmpData xmpData; + try { + xmpData["Xmp.dc.title"] = "lang=test3-6\"\""; + } + catch (AnyError& e) { + ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue); + } + catch (...) { + ASSERT_TRUE(false); + } +} + +// 4. Invalid characters in language part +TEST(LangAltValueReadTest, languageValExtraHyphenBeforeSpace) +{ + XmpParser::initialize(); + ::atexit(XmpParser::terminate); + + Exiv2::XmpData xmpData; + try { + xmpData["Xmp.dc.title"] = "lang=en-UK- test4-1"; + } + catch (AnyError& e) { + ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue); + } + catch (...) { + ASSERT_TRUE(false); + } +} + +TEST(LangAltValueReadTest, languageValWithInvalidCharBeforeSpace) +{ + XmpParser::initialize(); + ::atexit(XmpParser::terminate); + + Exiv2::XmpData xmpData; + try { + xmpData["Xmp.dc.title"] = "lang=en=UK test4-2"; + } + catch (AnyError& e) { + ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue); + } + catch (...) { + ASSERT_TRUE(false); + } +} From 5f563b52557cf9a38a09db4c7b05f118f9260d2b Mon Sep 17 00:00:00 2001 From: postscript-dev <43813-postscript-dev@users.noreply.gitlab.gnome.org> Date: Tue, 9 Mar 2021 12:13:48 +0000 Subject: [PATCH 4/5] Fix spelling mistakes in LangAltValue::read() Removed unneeded comments and empty space. --- src/value.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/value.cpp b/src/value.cpp index 180bbecdd8..579e4081ab 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -860,8 +860,8 @@ namespace Exiv2 { std::string b = buf; std::string lang = "x-default"; if (buf.length() > 5 && buf.substr(0, 5) == "lang=") { - static const char* ALPLHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - static const char* ALPLHA_NUM = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + static const char* ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + static const char* ALPHA_NUM = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; std::string::size_type pos = buf.find_first_of(' '); lang = buf.substr(5, pos-5); @@ -870,17 +870,17 @@ namespace Exiv2 { lang = lang.substr(1); if (lang == "" || lang.find('"') != lang.length()-1) - throw Error(kerInvalidLangAltValue, buf); // *** + throw Error(kerInvalidLangAltValue, buf); lang = lang.substr(0, lang.length()-1); } - if (lang == "") throw Error(kerInvalidLangAltValue, buf); // *** + if (lang == "") throw Error(kerInvalidLangAltValue, buf); // Check language is in the correct format (see https://www.ietf.org/rfc/rfc3066.txt) - std::string::size_type charPos = lang.find_first_not_of(ALPLHA); + std::string::size_type charPos = lang.find_first_not_of(ALPHA); if (charPos != std::string::npos) { - if (lang[charPos] != '-' || lang.find_first_not_of(ALPLHA_NUM, charPos+1) != std::string::npos) + if (lang[charPos] != '-' || lang.find_first_not_of(ALPHA_NUM, charPos+1) != std::string::npos) throw Error(kerInvalidLangAltValue, buf); } @@ -888,7 +888,6 @@ namespace Exiv2 { if (pos != std::string::npos) b = buf.substr(pos+1); } - value_[lang] = b; return 0; } From 2917b83d0ec46eb64cad1bc7af0c44e305a9d8e6 Mon Sep 17 00:00:00 2001 From: postscript-dev <43813-postscript-dev@users.noreply.gitlab.gnome.org> Date: Tue, 9 Mar 2021 15:59:48 +0000 Subject: [PATCH 5/5] Update exiv2 man page - langAlt format --- man/man1/exiv2.1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/man/man1/exiv2.1 b/man/man1/exiv2.1 index 08cee4f9e7..448ab14efc 100644 --- a/man/man1/exiv2.1 +++ b/man/man1/exiv2.1 @@ -584,12 +584,16 @@ The format of XMP \fBLangAlt\fP values includes an optional language qualifier: .B lang="\fIlanguage-code\fP\fI" text\fP .fi .sp -lang="x-default" is used if the value doesn't start with a language qualifier. +The double quotes around the \fIlanguage-code\fP are optional. If no languge qualifier +is supplied, then the value of "x-default" is used. More information +on the language format can be found at: https://www.ietf.org/rfc/rfc3066.txt .sp 1 .nf $ exiv2 -M'set Xmp.dc.title lang="de-DE" Euros' X.jpg $ exiv2 -M'set Xmp.dc.title lang="en-GB" Pounds' X.jpg $ exiv2 -M'set Xmp.dc.title lang="en-US" In God We Trust' X.jpg +$ exiv2 -M'set Xmp.dc.title lang=fr-FR Euros' X.jpg +$ exiv2 -M'set Xmp.dc.title lang=jp Yen' X.jpg $ exiv2 -M'set Xmp.dc.title All others pay cash' X.jpg .fi .sp 1