Skip to content

Commit 65fad9d

Browse files
Merge pull request #2007 from kevinbackhouse/FixIssue2006
Fix integer overflow in PanasonicMakerNote::printAccelerometer
2 parents aebb3fb + 35f48ae commit 65fad9d

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

src/panasonicmn_int.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -691,17 +691,15 @@ namespace Exiv2 {
691691

692692
std::ostream& PanasonicMakerNote::printAccelerometer(std::ostream& os, const Value& value, const ExifData*)
693693
{
694-
// value is stored as unsigned int, but should be readed as signed int, so manually convert it
695-
int i = value.toLong();
696-
i = i - ((i & 0x8000) >> 15) * 0xffff;
694+
// value is stored as unsigned int, but should be read as int16_t.
695+
const int16_t i = static_cast<int16_t>(value.toLong());
697696
return os << i;
698697
} // PanasonicMakerNote::printAccelerometer
699698

700699
std::ostream& PanasonicMakerNote::printRollAngle(std::ostream& os, const Value& value, const ExifData*)
701700
{
702-
// roll angle is stored as signed int, but tag states to be unsigned int
703-
int i = value.toLong();
704-
i = i - ((i & 0x8000) >> 15) * 0xffff;
701+
// value is stored as unsigned int, but should be read as int16_t.
702+
const int16_t i = static_cast<int16_t>(value.toLong());
705703
std::ostringstream oss;
706704
oss.copyfmt(os);
707705
os << std::fixed << std::setprecision(1) << i / 10.0;
@@ -712,10 +710,8 @@ namespace Exiv2 {
712710

713711
std::ostream& PanasonicMakerNote::printPitchAngle(std::ostream& os, const Value& value, const ExifData*)
714712
{
715-
// pitch angle is stored as signed int, but tag states to be unsigned int
716-
// change sign to be compatible with ExifTool: positive is upwards
717-
int i = value.toLong();
718-
i = i - ((i & 0x8000) >> 15) * 0xffff;
713+
// value is stored as unsigned int, but should be read as int16_t.
714+
const int16_t i = static_cast<int16_t>(value.toLong());
719715
std::ostringstream oss;
720716
oss.copyfmt(os);
721717
os << std::fixed << std::setprecision(1) << -i / 10.0;

test/data/issue_2006_poc.tiff

144 Bytes
Binary file not shown.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from system_tests import CaseMeta, path
4+
5+
class PanasonicMakerPrintAccelerometerIntOverflow(metaclass=CaseMeta):
6+
"""
7+
Regression test for the bug described in:
8+
https://github.com/Exiv2/exiv2/issues/2006
9+
"""
10+
url = "https://github.com/Exiv2/exiv2/issues/2006"
11+
12+
filename = path("$data_path/issue_2006_poc.tiff")
13+
commands = ["$exiv2 -q -PE $filename"]
14+
stderr = [""]
15+
stdout = ["""Exif.Image.Make Ascii 32 Panasonic
16+
Exif.Image.DNGPrivateData 0x2020 32 80 97 110 97 115 111 110 105 99 32 32 32 0 32 32 255 32 32 32 32 32 255 255 255 32 255 255 198 52 32 32 0
17+
Exif.MakerNote.Offset Long 1 48
18+
Exif.MakerNote.ByteOrder Ascii 3 MM
19+
Exif.Panasonic.AccelerometerY SLong 4 -224
20+
"""]
21+
retval = [0]

0 commit comments

Comments
 (0)