@@ -604,25 +604,20 @@ void Jp2Image::encodeJp2Header(const DataBuf& boxBuf, DataBuf& outBuf) {
604604 size_t outlen = boxHSize; // now many bytes have we written to output?
605605 size_t inlen = boxHSize; // how many bytes have we read from boxBuf?
606606 enforce (boxHSize <= output.size (), ErrorCode::kerCorruptedMetadata);
607- auto pBox = reinterpret_cast <const Internal::Jp2BoxHeader*>(boxBuf.c_data ());
608- uint32_t length = getLong (reinterpret_cast <const byte*>(&pBox->length ), bigEndian);
607+ uint32_t length = getLong (boxBuf.c_data (0 ), bigEndian);
609608 enforce (length <= output.size (), ErrorCode::kerCorruptedMetadata);
610609 uint32_t count = boxHSize;
611- auto p = boxBuf.c_str ();
612610 bool bWroteColor = false ;
613611
614612 while (count < length && !bWroteColor) {
615613 enforce (boxHSize <= length - count, ErrorCode::kerCorruptedMetadata);
616- auto pSubBox = reinterpret_cast <const Internal::Jp2BoxHeader*>(p + count);
617-
618- // copy data. pointer could be into a memory mapped file which we will decode!
619614 Internal::Jp2BoxHeader subBox;
620- memcpy (&subBox, pSubBox , boxHSize);
615+ memcpy (&subBox, boxBuf. c_data (count) , boxHSize);
621616 Internal::Jp2BoxHeader newBox = subBox;
622617
623618 if (count < length) {
624- subBox.length = getLong (reinterpret_cast <byte*>(&subBox. length ), bigEndian);
625- subBox.type = getLong (reinterpret_cast <byte*>(&subBox. type ), bigEndian);
619+ subBox.length = getLong (boxBuf. c_data (count ), bigEndian);
620+ subBox.type = getLong (boxBuf. c_data (count + 4 ), bigEndian);
626621#ifdef EXIV2_DEBUG_MESSAGES
627622 std::cout << " Jp2Image::encodeJp2Header subbox: " << toAscii (subBox.type ) << " length = " << subBox.length
628623 << std::endl;
@@ -671,9 +666,8 @@ void Jp2Image::encodeJp2Header(const DataBuf& boxBuf, DataBuf& outBuf) {
671666 // allocate the correct number of bytes, copy the data and update the box header
672667 outBuf.alloc (outlen);
673668 std::copy_n (output.c_data (), outlen, outBuf.begin ());
674- auto oBox = reinterpret_cast <Internal::Jp2BoxHeader*>(outBuf.data ());
675- ul2Data (reinterpret_cast <byte*>(&oBox->type ), kJp2BoxTypeHeader , bigEndian);
676- ul2Data (reinterpret_cast <byte*>(&oBox->length ), static_cast <uint32_t >(outlen), bigEndian);
669+ ul2Data (outBuf.data (0 ), static_cast <uint32_t >(outlen), bigEndian);
670+ ul2Data (outBuf.data (4 ), kJp2BoxTypeHeader , bigEndian);
677671}
678672
679673#ifdef __clang__
0 commit comments