summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorJulien Nabet <serval2412@yahoo.fr>2013-10-15 07:57:52 +0200
committerCaolán McNamara <caolanm@redhat.com>2013-10-15 09:20:00 +0000
commit3ad12d1a540eeb54fbb34afc3b7a76bf9e3207c3 (patch)
tree59dba990d0c45789e134d049250be03fe49f79d5 /vcl
parentb122ec243bc5aff15a8e3e9c06aea65d61337ee9 (diff)
fdo#57659: fix exif processing
Change-Id: I93bd132b1d536843d4d8627230bfa9ef22cd623b Reviewed-on: https://gerrit.libreoffice.org/6245 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/filter/jpeg/Exif.cxx48
-rw-r--r--vcl/source/filter/jpeg/Exif.hxx3
2 files changed, 41 insertions, 10 deletions
diff --git a/vcl/source/filter/jpeg/Exif.cxx b/vcl/source/filter/jpeg/Exif.cxx
index f44b54f420f5..3a4b2d379a6e 100644
--- a/vcl/source/filter/jpeg/Exif.cxx
+++ b/vcl/source/filter/jpeg/Exif.cxx
@@ -156,15 +156,20 @@ bool Exif::processJpeg(SvStream& rStream, bool bSetValue)
return false;
}
-bool Exif::processIFD(sal_uInt8* pExifData, sal_uInt16 aLength, sal_uInt16 aOffset, sal_uInt16 aNumberOfTags, bool bSetValue)
+bool Exif::processIFD(sal_uInt8* pExifData, sal_uInt16 aLength, sal_uInt16 aOffset, sal_uInt16 aNumberOfTags, bool bSetValue, bool bMoto)
{
ExifIFD* ifd = NULL;
while (aOffset <= aLength - 12 && aNumberOfTags > 0)
{
ifd = (ExifIFD*) &pExifData[aOffset];
+ sal_uInt16 tag = ifd->tag;
+ if (bMoto)
+ {
+ tag = OSL_SWAPWORD(ifd->tag);
+ }
- if (ifd->tag == ORIENTATION)
+ if (tag == ORIENTATION)
{
if(bSetValue)
{
@@ -172,10 +177,18 @@ bool Exif::processIFD(sal_uInt8* pExifData, sal_uInt16 aLength, sal_uInt16 aOffs
ifd->type = 3;
ifd->count = 1;
ifd->offset = maOrientation;
+ if (bMoto)
+ {
+ ifd->tag = OSL_SWAPWORD(ifd->tag);
+ ifd->offset = OSL_SWAPWORD(ifd->offset);
+ }
}
else
{
- maOrientation = convertToOrientation(ifd->offset);
+ sal_uInt32 nIfdOffset = ifd->offset;
+ if (bMoto)
+ nIfdOffset = OSL_SWAPWORD(ifd->offset);
+ maOrientation = convertToOrientation(nIfdOffset);
}
}
@@ -211,20 +224,37 @@ bool Exif::processExif(SvStream& rStream, sal_uInt16 aSectionLength, bool bSetVa
TiffHeader* aTiffHeader = (TiffHeader*) &aExifData[0];
- if( 0x4949 != aTiffHeader->byteOrder || 0x002A != aTiffHeader->tagAlign )
+ if(!(
+ (0x4949 == aTiffHeader->byteOrder && 0x2A00 != aTiffHeader->tagAlign ) || // Intel format
+ ( 0x4D4D == aTiffHeader->byteOrder && 0x002A != aTiffHeader->tagAlign ) // Motorola format
+ )
+ )
{
delete[] aExifData;
return false;
}
- sal_uInt16 aOffset = aTiffHeader->offset;
+ bool bMoto = true; // Motorola, big-endian by default
+
+ if (aTiffHeader->byteOrder == 0x4949)
+ {
+ bMoto = false; // little-endian
+ }
+
+ sal_uInt16 aOffset = 0;
+ aOffset = aTiffHeader->offset;
+ if (bMoto)
+ {
+ aOffset = OSL_SWAPDWORD(aTiffHeader->offset);
+ }
sal_uInt16 aNumberOfTags = aExifData[aOffset];
- aNumberOfTags = aExifData[aOffset + 1];
- aNumberOfTags <<= 8;
- aNumberOfTags += aExifData[aOffset];
+ if (bMoto)
+ {
+ aNumberOfTags = ((aExifData[aOffset] << 8) | aExifData[aOffset+1]);
+ }
- processIFD(aExifData, aLength, aOffset+2, aNumberOfTags, bSetValue);
+ processIFD(aExifData, aLength, aOffset+2, aNumberOfTags, bSetValue, bMoto);
if (bSetValue)
{
diff --git a/vcl/source/filter/jpeg/Exif.hxx b/vcl/source/filter/jpeg/Exif.hxx
index 490f144949cd..40faa581d593 100644
--- a/vcl/source/filter/jpeg/Exif.hxx
+++ b/vcl/source/filter/jpeg/Exif.hxx
@@ -20,6 +20,7 @@
#ifndef _EXIF_HXX
#define _EXIF_HXX
+#include <osl/endian.h>
#include <vcl/graph.hxx>
#include <vcl/fltcall.hxx>
#include <com/sun/star/uno/Sequence.h>
@@ -53,7 +54,7 @@ private:
bool processJpeg(SvStream& rStream, bool bSetValue);
bool processExif(SvStream& rStream, sal_uInt16 aLength, bool bSetValue);
- bool processIFD(sal_uInt8* pExifData, sal_uInt16 aLength, sal_uInt16 aOffset, sal_uInt16 aNumberOfTags, bool bSetValue);
+ bool processIFD(sal_uInt8* pExifData, sal_uInt16 aLength, sal_uInt16 aOffset, sal_uInt16 aNumberOfTags, bool bSetValue, bool bMoto);
struct ExifIFD {
sal_uInt16 tag;