[Libreoffice-commits] core.git: vcl/source
Julien Nabet
serval2412 at yahoo.fr
Tue Oct 15 02:20:21 PDT 2013
vcl/source/filter/jpeg/Exif.cxx | 48 ++++++++++++++++++++++++++++++++--------
vcl/source/filter/jpeg/Exif.hxx | 3 +-
2 files changed, 41 insertions(+), 10 deletions(-)
New commits:
commit 3ad12d1a540eeb54fbb34afc3b7a76bf9e3207c3
Author: Julien Nabet <serval2412 at yahoo.fr>
Date: Tue Oct 15 07:57:52 2013 +0200
fdo#57659: fix exif processing
Change-Id: I93bd132b1d536843d4d8627230bfa9ef22cd623b
Reviewed-on: https://gerrit.libreoffice.org/6245
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/vcl/source/filter/jpeg/Exif.cxx b/vcl/source/filter/jpeg/Exif.cxx
index f44b54f..3a4b2d3 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 490f144..40faa58 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;
More information about the Libreoffice-commits
mailing list