Skip to content

Commit 06516e3

Browse files
lgritzscott-wilson
authored andcommitted
int: Address safety warnings in pvt::append_tiff_dir_entry (AcademySoftwareFoundation#4737)
I think what we were doing here was fine all along, but the idiom was confusing to static analyzers who identified a danger that we were memcpy'ing into a field that was potentially not big enough. A minor restructuring of the code and a new assertion should verify that it's safe and also make it clear to the static analyzer that we aren't falling into the case it warned about. Signed-off-by: Larry Gritz <[email protected]> Signed-off-by: Scott Wilson <[email protected]>
1 parent 598a5d9 commit 06516e3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/libOpenImageIO/exif.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,15 +1092,17 @@ pvt::append_tiff_dir_entry(std::vector<TIFFDirEntry>& dirs,
10921092
dir.tdir_tag = tag;
10931093
dir.tdir_type = type;
10941094
dir.tdir_count = count;
1095+
dir.tdir_offset = 0;
10951096
size_t len = tiff_data_size(dir);
10961097
char* ptr = nullptr;
10971098
bool data_in_offset = false;
10981099
if (len <= 4) {
10991100
dir.tdir_offset = 0;
11001101
data_in_offset = true;
11011102
if (mydata.size()) {
1103+
OIIO_DASSERT(len == mydata.size());
11021104
ptr = (char*)&dir.tdir_offset;
1103-
memcpy(ptr, mydata.data(), mydata.size());
1105+
memcpy(ptr, mydata.data(), len);
11041106
}
11051107
} else {
11061108
if (mydata.size()) {

0 commit comments

Comments
 (0)