Index: tiffcomposite.cpp =================================================================== --- tiffcomposite.cpp (revision 2561) +++ tiffcomposite.cpp (revision 2562) @@ -1689,11 +1689,19 @@ if (elements_.empty()) return 0; + // Remaining assumptions: + // - array elements don't "overlap" + // - no duplicate tags in the array uint32_t idx = 0; + uint32_t sz = cfg()->tagStep(); for (Components::const_iterator i = elements_.begin(); i != elements_.end(); ++i) { - idx = EXV_MAX(idx, (*i)->tag() * cfg()->tagStep()); - idx += (*i)->size(); + if ((*i)->tag() > idx) { + idx = (*i)->tag(); + sz = (*i)->size(); + } } + idx = idx * cfg()->tagStep() + sz; + if (cfg()->hasFillers_ && def()) { const ArrayDef* lastDef = def() + defSize() - 1; uint16_t lastTag = static_cast<uint16_t>(lastDef->idx_ / cfg()->tagStep());