Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Makernotes handling: #302

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion src/librawspeed/tiff/TiffIFD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ TiffRootIFDOwner TiffIFD::parseMakerNote(NORangesSet<Buffer>* ifds,
string make = makeEntry != nullptr ? trimSpaces(makeEntry->getString()) : "";

ByteStream bs = t->getData();
auto bufbegin = bs.begin() + bs.getPosition();

// helper function for easy setup of ByteStream buffer for the different maker note types
// 'rebase' means position 0 of new stream equals current position
Expand All @@ -159,7 +160,9 @@ TiffRootIFDOwner TiffIFD::parseMakerNote(NORangesSet<Buffer>* ifds,
bs.skipBytes(newPosition);
};

if (bs.hasPrefix("AOC\0", 4)) {
if (bs.hasPrefix("LSI1\0", 5)) { // Skip LSI1 makernotes
Copy link
Collaborator

@kmilos kmilos Sep 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe be more verbose in the comments that this indicates "LaserSoft Imaging (SilverFast)" for posterity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the text of the comment is the only thing that prevents Roman from accepting this patch, then I will certainly change it. Let's wait for his opinion.

return std::make_unique<TiffRootIFD>(this, ifds, bs, UINT32_MAX); // UINT32_MAX offset => special handling, empty IFD
} else if (bs.hasPrefix("AOC\0", 4)) {
setup(false, 6, 4, "Pentax makernote");
} else if (bs.hasPrefix("PENTAX", 6)) {
setup(true, 10, 8, "Pentax makernote");
Expand Down Expand Up @@ -197,6 +200,12 @@ TiffRootIFDOwner TiffIFD::parseMakerNote(NORangesSet<Buffer>* ifds,
}
}

auto readed = bs.begin() - bufbegin + bs.getPosition();
ByteStream bscheck(bs);
const auto IFDSize = 6 + 12 * bscheck.getU16();

if(IFDSize > t->count - readed) // IFDSize too big, probably binary Makernotes dir, not TIFF-like, could not be handled by TiffRootIFD reader
return std::make_unique<TiffRootIFD>(this, ifds, bs, UINT32_MAX); // // UINT32_MAX offset => special handling, empty IFD
// Attempt to parse the rest as an IFD
return std::make_unique<TiffRootIFD>(this, ifds, bs, bs.getPosition());
}
Expand Down