From 29df4e8218ee7d147542f767d899c5c639932e06 Mon Sep 17 00:00:00 2001 From: Andrew Au Date: Wed, 8 May 2019 10:35:43 -0700 Subject: Return the required padding size instead of the current position to avoid integer overflow. --- src/vm/eventpipeblock.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/vm/eventpipeblock.h') diff --git a/src/vm/eventpipeblock.h b/src/vm/eventpipeblock.h index 78b04af805..c85a84e461 100644 --- a/src/vm/eventpipeblock.h +++ b/src/vm/eventpipeblock.h @@ -51,14 +51,13 @@ public: if (eventsSize == 0) return; - size_t currentPosition = pSerializer->GetCurrentPosition(); - if (currentPosition % ALIGNMENT_SIZE != 0) + unsigned int requiredPadding = pSerializer->GetRequiredPadding(); + if (requiredPadding != 0) { BYTE maxPadding[ALIGNMENT_SIZE - 1] = {}; // it's longest possible padding, we are going to use only part of it - unsigned int paddingLength = ALIGNMENT_SIZE - (currentPosition % ALIGNMENT_SIZE); - pSerializer->WriteBuffer(maxPadding, paddingLength); // we write zeros here, the reader is going to always read from the first aligned address of the serialized content + pSerializer->WriteBuffer(maxPadding, requiredPadding); // we write zeros here, the reader is going to always read from the first aligned address of the serialized content - _ASSERTE(pSerializer->HasWriteErrors() || (pSerializer->GetCurrentPosition() % ALIGNMENT_SIZE == 0)); + _ASSERTE(pSerializer->HasWriteErrors() || (pSerializer->GetRequiredPadding() == 0)); } pSerializer->WriteBuffer(m_pBlock, eventsSize); -- cgit v1.2.3