Skip to content

Commit

Permalink
add null dynamic_cast checks
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Jul 2, 2023
1 parent 4c4bf7c commit 4783581
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/tiffcomposite_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ size_t TiffBinaryArray::addElement(size_t idx, const ArrayDef& def) {
auto sz = std::min<size_t>(def.size(tag, cfg()->group_), TiffEntryBase::doSize() - idx);
auto tc = TiffCreator::create(tag, cfg()->group_);
auto tp = dynamic_cast<TiffBinaryElement*>(tc.get());
if (!tp)
return 0;
// The assertion typically fails if a component is not configured in
// the TIFF structure table (TiffCreator::tiffTreeStruct_)
tp->setStart(pData() + idx);
Expand Down Expand Up @@ -917,6 +919,8 @@ size_t TiffDirectory::doWrite(IoWrapper& ioWrapper, ByteOrder byteOrder, size_t
size_t TiffDirectory::writeDirEntry(IoWrapper& ioWrapper, ByteOrder byteOrder, size_t offset,
TiffComponent* pTiffComponent, size_t valueIdx, size_t dataIdx, size_t& imageIdx) {
auto pDirEntry = dynamic_cast<TiffEntryBase*>(pTiffComponent);
if (!pDirEntry)
return 0;
byte buf[8];
us2Data(buf, pDirEntry->tag(), byteOrder);
us2Data(buf + 2, pDirEntry->tiffType(), byteOrder);
Expand Down
2 changes: 2 additions & 0 deletions src/tiffvisitor_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ void TiffEncoder::visitDirectoryNext(TiffDirectory* object) {

uint32_t TiffEncoder::updateDirEntry(byte* buf, ByteOrder byteOrder, TiffComponent* pTiffComponent) {
auto pTiffEntry = dynamic_cast<TiffEntryBase*>(pTiffComponent);
if (!pTiffEntry)
return 0;
us2Data(buf + 2, pTiffEntry->tiffType(), byteOrder);
ul2Data(buf + 4, static_cast<uint32_t>(pTiffEntry->count()), byteOrder);
// Move data to offset field, if it fits and is not yet there.
Expand Down

0 comments on commit 4783581

Please sign in to comment.