Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified autotest/gdrivers/data/jpeg2000/byte_lossless_openjp2_golden.jp2
Binary file not shown.
8 changes: 5 additions & 3 deletions gcore/gdaljp2box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ GDALJP2Box *GDALJP2Box::CreateLblBox(const char *pszLabel)
{
GDALJP2Box *const poBox = new GDALJP2Box();
poBox->SetType("lbl ");
poBox->SetWritableData(static_cast<int>(strlen(pszLabel) + 1),
poBox->SetWritableData(static_cast<int>(strlen(pszLabel)),
reinterpret_cast<const GByte *>(pszLabel));

return poBox;
Expand All @@ -504,12 +504,12 @@ GDALJP2Box *GDALJP2Box::CreateLabelledXMLAssoc(const char *pszLabel,
{
GDALJP2Box oLabel;
oLabel.SetType("lbl ");
oLabel.SetWritableData(static_cast<int>(strlen(pszLabel) + 1),
oLabel.SetWritableData(static_cast<int>(strlen(pszLabel)),
reinterpret_cast<const GByte *>(pszLabel));

GDALJP2Box oXML;
oXML.SetType("xml ");
oXML.SetWritableData(static_cast<int>(strlen(pszXML) + 1),
oXML.SetWritableData(static_cast<int>(strlen(pszXML)),
reinterpret_cast<const GByte *>(pszXML));

GDALJP2Box *aoList[2] = {&oLabel, &oXML};
Expand All @@ -530,6 +530,8 @@ GDALJP2Box *GDALJP2Box::CreateJUMBFDescriptionBox(const GByte *pabyUUIDType,

poBox->AppendWritableData(16, pabyUUIDType);
poBox->AppendUInt8(3); // requestable field
// +1 since NUL terminated byte required in the JUMBF spec
// cf other implementation at https://gitlab.com/wg1/jpeg-systems/reference-software/jumbf-reference-implementation-2/-/blame/main/dbench_jumbf/src/db_jumbf_desc_box.cpp?ref_type=heads#L169
const size_t nLabelLen = strlen(pszLabel) + 1;
poBox->AppendWritableData(static_cast<int>(nLabelLen), pszLabel);

Expand Down
12 changes: 6 additions & 6 deletions gcore/gdaljp2metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ void GDALJP2Metadata::CollectGMLData(GDALJP2Box *poGMLData)

while (strlen(oSubChildBox.GetType()) > 0)
{
if (EQUAL(oSubChildBox.GetType(), "lbl "))
if (EQUAL(oSubChildBox.GetType(), "lbl ") && !pszLabel)
pszLabel =
reinterpret_cast<char *>(oSubChildBox.ReadBoxData());
else if (EQUAL(oSubChildBox.GetType(), "xml "))
else if (EQUAL(oSubChildBox.GetType(), "xml ") && !pszXML)
{
pszXML =
reinterpret_cast<char *>(oSubChildBox.ReadBoxData());
Expand Down Expand Up @@ -3333,7 +3333,7 @@ GDALJP2Metadata::CreateGDALMultiDomainMetadataXMLBox(GDALDataset *poSrcDS,

GDALJP2Box *poBox = new GDALJP2Box();
poBox->SetType("xml ");
poBox->SetWritableData(static_cast<int>(strlen(pszXML) + 1),
poBox->SetWritableData(static_cast<int>(strlen(pszXML)),
reinterpret_cast<const GByte *>(pszXML));
CPLFree(pszXML);

Expand Down Expand Up @@ -3362,7 +3362,7 @@ GDALJP2Box **GDALJP2Metadata::CreateXMLBoxes(GDALDataset *poSrcDS, int *pnBoxes)
GDALJP2Box *poBox = new GDALJP2Box();
poBox->SetType("xml ");
poBox->SetWritableData(
static_cast<int>(strlen(*papszSrcMD) + 1),
static_cast<int>(strlen(*papszSrcMD)),
reinterpret_cast<const GByte *>(*papszSrcMD));
papoBoxes = static_cast<GDALJP2Box **>(CPLRealloc(
papoBoxes, sizeof(GDALJP2Box *) * (*pnBoxes + 1)));
Expand All @@ -3385,7 +3385,7 @@ GDALJP2Box *GDALJP2Metadata::CreateXMPBox(GDALDataset *poSrcDS)
if (papszSrcMD && *papszSrcMD)
{
poBox = GDALJP2Box::CreateUUIDBox(
xmp_uuid, static_cast<int>(strlen(*papszSrcMD) + 1),
xmp_uuid, static_cast<int>(strlen(*papszSrcMD)),
reinterpret_cast<const GByte *>(*papszSrcMD));
}
return poBox;
Expand All @@ -3403,7 +3403,7 @@ GDALJP2Box *GDALJP2Metadata::CreateIPRBox(GDALDataset *poSrcDS)
{
poBox = new GDALJP2Box();
poBox->SetType("jp2i");
poBox->SetWritableData(static_cast<int>(strlen(*papszSrcMD) + 1),
poBox->SetWritableData(static_cast<int>(strlen(*papszSrcMD)),
reinterpret_cast<const GByte *>(*papszSrcMD));
}
return poBox;
Expand Down
Loading