vcl/source/filter/jpeg/Exif.cxx | 55 ++++++++++++++++++++++++++++++++++------ vcl/source/filter/jpeg/Exif.hxx | 3 +- 2 files changed, 49 insertions(+), 9 deletions(-)
New commits: commit 69f026fc37cc5be080c02497e8fe3e0b88efa913 Author: Caolán McNamara <caol...@redhat.com> Date: Tue Oct 15 10:21:35 2013 +0100 swap if the host endianness doesn't match the file formats Change-Id: I0b4c2ba6679c8d2754f2a7cd8b8f693db335e004 Reviewed-on: https://gerrit.libreoffice.org/6408 Tested-by: Caolán McNamara <caol...@redhat.com> Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/vcl/source/filter/jpeg/Exif.cxx b/vcl/source/filter/jpeg/Exif.cxx index 3a4b2d3..cf64f9b 100644 --- a/vcl/source/filter/jpeg/Exif.cxx +++ b/vcl/source/filter/jpeg/Exif.cxx @@ -156,7 +156,7 @@ 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 bMoto) +bool Exif::processIFD(sal_uInt8* pExifData, sal_uInt16 aLength, sal_uInt16 aOffset, sal_uInt16 aNumberOfTags, bool bSetValue, bool bSwap) { ExifIFD* ifd = NULL; @@ -164,7 +164,7 @@ bool Exif::processIFD(sal_uInt8* pExifData, sal_uInt16 aLength, sal_uInt16 aOffs { ifd = (ExifIFD*) &pExifData[aOffset]; sal_uInt16 tag = ifd->tag; - if (bMoto) + if (bSwap) { tag = OSL_SWAPWORD(ifd->tag); } @@ -177,7 +177,7 @@ bool Exif::processIFD(sal_uInt8* pExifData, sal_uInt16 aLength, sal_uInt16 aOffs ifd->type = 3; ifd->count = 1; ifd->offset = maOrientation; - if (bMoto) + if (bSwap) { ifd->tag = OSL_SWAPWORD(ifd->tag); ifd->offset = OSL_SWAPWORD(ifd->offset); @@ -186,7 +186,7 @@ bool Exif::processIFD(sal_uInt8* pExifData, sal_uInt16 aLength, sal_uInt16 aOffs else { sal_uInt32 nIfdOffset = ifd->offset; - if (bMoto) + if (bSwap) nIfdOffset = OSL_SWAPWORD(ifd->offset); maOrientation = convertToOrientation(nIfdOffset); } @@ -224,37 +224,46 @@ bool Exif::processExif(SvStream& rStream, sal_uInt16 aSectionLength, bool bSetVa TiffHeader* aTiffHeader = (TiffHeader*) &aExifData[0]; - if(!( - (0x4949 == aTiffHeader->byteOrder && 0x2A00 != aTiffHeader->tagAlign ) || // Intel format - ( 0x4D4D == aTiffHeader->byteOrder && 0x002A != aTiffHeader->tagAlign ) // Motorola format - ) - ) + bool bIntel = aTiffHeader->byteOrder == 0x4949; //big-endian + bool bMotorola = aTiffHeader->byteOrder == 0x4D4D; //little-endian + + if (!bIntel && !bMotorola) { delete[] aExifData; return false; } - bool bMoto = true; // Motorola, big-endian by default + bool bSwap = false; + +#ifdef OSL_BIGENDIAN + if (bIntel) + bSwap = true; +#else + if (bMotorola) + bSwap = true; +#endif - if (aTiffHeader->byteOrder == 0x4949) + if (bSwap) { - bMoto = false; // little-endian + aTiffHeader->tagAlign = OSL_SWAPWORD(aTiffHeader->tagAlign); + aTiffHeader->offset = OSL_SWAPDWORD(aTiffHeader->offset); } - sal_uInt16 aOffset = 0; - aOffset = aTiffHeader->offset; - if (bMoto) + if (aTiffHeader->tagAlign != 0x002A) // TIFF tag { - aOffset = OSL_SWAPDWORD(aTiffHeader->offset); + delete[] aExifData; + return false; } + sal_uInt16 aOffset = aTiffHeader->offset; + sal_uInt16 aNumberOfTags = aExifData[aOffset]; - if (bMoto) + if (bSwap) { aNumberOfTags = ((aExifData[aOffset] << 8) | aExifData[aOffset+1]); } - processIFD(aExifData, aLength, aOffset+2, aNumberOfTags, bSetValue, bMoto); + processIFD(aExifData, aLength, aOffset+2, aNumberOfTags, bSetValue, bSwap); if (bSetValue) { commit fc7b83af9865bfd937cf45242781a8d7677f6204 Author: Julien Nabet <serval2...@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 <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> Reviewed-on: https://gerrit.libreoffice.org/6407 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;
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits