correctly write padding for MxSts

This commit is contained in:
MattKC 2023-09-17 14:13:02 -07:00
parent cc4534c999
commit 4009e0c278
2 changed files with 15 additions and 6 deletions

View file

@ -404,6 +404,9 @@ Interleaf::Error Interleaf::Write(FileBase *f) const
continue;
}
size_t maxSz = child->CalculateMaximumDiskSize() + kMinimumChunkSize;
WritePaddingIfNecessary(f, maxSz);
uint32_t mxst_offset = f->pos();
f->seek(size_t(offset_table_pos) + i * sizeof(uint32_t));
@ -455,12 +458,7 @@ Interleaf::Error Interleaf::Write(FileBase *f) const
void Interleaf::WriteObject(FileBase *f, const Object *o) const
{
size_t projected_end = f->pos() + o->CalculateMaximumDiskSize();
size_t this_buf = f->pos()/m_BufferSize;
size_t end_buf = projected_end/m_BufferSize;
if (this_buf != end_buf) {
WritePadding(f, (end_buf * m_BufferSize) - f->pos());
}
WritePaddingIfNecessary(f, o->CalculateMaximumDiskSize());
RIFF::Chk mxob = RIFF::BeginChunk(f, RIFF::MxOb);
@ -747,4 +745,14 @@ void Interleaf::WritePadding(FileBase *f, uint32_t size) const
f->WriteBytes(b);
}
void Interleaf::WritePaddingIfNecessary(FileBase *f, size_t projectedWrite) const
{
size_t projected_end = f->pos() + projectedWrite;
size_t this_buf = f->pos()/m_BufferSize;
size_t end_buf = projected_end/m_BufferSize;
if (this_buf != end_buf) {
WritePadding(f, (end_buf * m_BufferSize) - f->pos());
}
}
}

View file

@ -50,6 +50,7 @@ private:
void WriteSubChunkInternal(FileBase *f, uint16_t flags, uint32_t object, uint32_t time, uint32_t data_sz, const bytearray &data) const;
void WritePadding(FileBase *f, uint32_t size) const;
void WritePaddingIfNecessary(FileBase *f, size_t projectedWrite) const;
Info m_Info;