Merge pull request #1486 from Exiv2/fix_1484_empty_ascii

Terminate empty ASCII strings
This commit is contained in:
Miloš Komarčević 2021-03-11 21:43:20 +01:00 committed by GitHub
commit b3dfabdde0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -410,7 +410,8 @@ namespace Exiv2 {
int AsciiValue::read(const std::string& buf)
{
value_ = buf;
if (value_.size() > 0 && value_[value_.size()-1] != '\0') value_ += '\0';
// ensure count>0 and nul terminated # https://github.com/Exiv2/exiv2/issues/1484
if (value_.size() == 0 || (value_.size() > 0 && value_[value_.size()-1] != '\0')) value_ += '\0';
return 0;
}

View File

@ -0,0 +1,28 @@
# -*- 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"
, "$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
""","","","",
"""Exif.Image.Copyright Ascii 1
""","",
"""Exif.Image.Copyright Ascii 9 me 2021-
"""]
stderr = [""]*len(commands)
retval = [1,0,0,0,1,0,0,0,0]