From 26ba26e241e10bcac91fac8ce3f0b5a4dd7a45cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Komar=C4=8Devi=C4=87?= Date: Wed, 10 Mar 2021 21:44:12 +0100 Subject: [PATCH 1/3] Terminate empty ASCII strings as well --- src/value.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/value.cpp b/src/value.cpp index 579e4081..2b412074 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -410,7 +410,7 @@ namespace Exiv2 { int AsciiValue::read(const std::string& buf) { value_ = buf; - if (value_.size() > 0 && value_[value_.size()-1] != '\0') value_ += '\0'; + if (value_.size() == 0 || value_[value_.size()-1] != '\0') value_ += '\0'; return 0; } From fa41e52c8a502d4b5a69dab406269cec1c7bc2c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Komar=C4=8Devi=C4=87?= Date: Thu, 11 Mar 2021 14:26:50 +0100 Subject: [PATCH 2/3] Add comment and test case --- src/value.cpp | 1 + tests/bugfixes/github/test_issue_1484.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/bugfixes/github/test_issue_1484.py diff --git a/src/value.cpp b/src/value.cpp index 2b412074..e02e465e 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -410,6 +410,7 @@ namespace Exiv2 { int AsciiValue::read(const std::string& buf) { value_ = buf; + // ensure count>0 and nul terminated # https://github.com/Exiv2/exiv2/issues/1484 if (value_.size() == 0 || value_[value_.size()-1] != '\0') value_ += '\0'; return 0; } diff --git a/tests/bugfixes/github/test_issue_1484.py b/tests/bugfixes/github/test_issue_1484.py new file mode 100644 index 00000000..d9a7e8e7 --- /dev/null +++ b/tests/bugfixes/github/test_issue_1484.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- + +from system_tests import CaseMeta, CopyTmpFiles, path +@CopyTmpFiles("$data_path/Stonehenge.exv") + +class test_issue_1484(metaclass=CaseMeta): + url = "https://github.com/Exiv2/exiv2/issues/1484" + filename = path("$tmp_path/Stonehenge.exv") + commands = [ "$exiv2 -g Copyright $filename" + , "$exiv2 -M\"set Exif.Image.Copyright Ascii ''\" $filename" + , "$exiv2 -g Copyright $filename" + ] + stdout = ["","","""Exif.Image.Copyright Ascii 1 +"""] + stderr = [""]*len(commands) + retval = [ 1,0,0] From ba6a577ab901cf32846dfdc65e5216417f3b5507 Mon Sep 17 00:00:00 2001 From: clanmills Date: Thu, 11 Mar 2021 18:31:52 +0000 Subject: [PATCH 3/3] https://github.com/Exiv2/exiv2/pull/1486#issuecomment-796843835 --- src/value.cpp | 2 +- tests/bugfixes/github/test_issue_1484.py | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/value.cpp b/src/value.cpp index e02e465e..d2ef5fbd 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -411,7 +411,7 @@ namespace Exiv2 { { value_ = buf; // ensure count>0 and nul terminated # https://github.com/Exiv2/exiv2/issues/1484 - if (value_.size() == 0 || value_[value_.size()-1] != '\0') value_ += '\0'; + if (value_.size() == 0 || (value_.size() > 0 && value_[value_.size()-1] != '\0')) value_ += '\0'; return 0; } diff --git a/tests/bugfixes/github/test_issue_1484.py b/tests/bugfixes/github/test_issue_1484.py index d9a7e8e7..6a3ce1cd 100644 --- a/tests/bugfixes/github/test_issue_1484.py +++ b/tests/bugfixes/github/test_issue_1484.py @@ -9,8 +9,20 @@ class test_issue_1484(metaclass=CaseMeta): commands = [ "$exiv2 -g Copyright $filename" , "$exiv2 -M\"set Exif.Image.Copyright Ascii ''\" $filename" , "$exiv2 -g Copyright $filename" + , "$exiv2 -M\"del Exif.Image.Copyright Ascii\" $filename" + , "$exiv2 -g Copyright $filename" + , "$exiv2 -M\"set Exif.Image.Copyright\" $filename" + , "$exiv2 -g Copyright $filename" + , "$exiv2 -M\"set Exif.Image.Copyright me 2021-\" $filename" + , "$exiv2 -g Copyright $filename" ] - stdout = ["","","""Exif.Image.Copyright Ascii 1 + stdout = ["","", +"""Exif.Image.Copyright Ascii 1 +""","","","", +"""Exif.Image.Copyright Ascii 1 +""","", +"""Exif.Image.Copyright Ascii 9 me 2021- """] stderr = [""]*len(commands) - retval = [ 1,0,0] + retval = [1,0,0,0,1,0,0,0,0] + \ No newline at end of file