summaryrefslogtreecommitdiff
path: root/src/vm
diff options
context:
space:
mode:
authorAndrew Au <andrewau@microsoft.com>2019-05-08 10:35:43 -0700
committerAndrew Au <cshung@gmail.com>2019-05-08 23:51:05 -0700
commit29df4e8218ee7d147542f767d899c5c639932e06 (patch)
tree80dfe8cf9c77b815fe381d25a39e8078c284f9a0 /src/vm
parent597e5faa03773e3140850d16381c00a6f9d20335 (diff)
downloadcoreclr-29df4e8218ee7d147542f767d899c5c639932e06.tar.gz
coreclr-29df4e8218ee7d147542f767d899c5c639932e06.tar.bz2
coreclr-29df4e8218ee7d147542f767d899c5c639932e06.zip
Return the required padding size instead of the current position to avoid integer overflow.
Diffstat (limited to 'src/vm')
-rw-r--r--src/vm/eventpipeblock.h9
-rw-r--r--src/vm/fastserializer.cpp11
-rw-r--r--src/vm/fastserializer.h6
3 files changed, 9 insertions, 17 deletions
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);
diff --git a/src/vm/fastserializer.cpp b/src/vm/fastserializer.cpp
index 3330bffc2f..73a8da553e 100644
--- a/src/vm/fastserializer.cpp
+++ b/src/vm/fastserializer.cpp
@@ -132,7 +132,7 @@ FastSerializer::FastSerializer(StreamWriter *pStreamWriter) : m_pStreamWriter(pS
CONTRACTL_END;
m_writeErrorEncountered = false;
- m_currentPos = 0;
+ m_requiredPadding = 0;
WriteFileHeader();
}
@@ -190,19 +190,12 @@ void FastSerializer::WriteBuffer(BYTE *pBuffer, unsigned int length)
uint32_t outCount;
bool fSuccess = m_pStreamWriter->Write(pBuffer, length, outCount);
-#ifdef _DEBUG
- size_t prevPos = m_currentPos;
-#endif
- m_currentPos += outCount;
+ m_requiredPadding = (ALIGNMENT_SIZE + m_requiredPadding - (outCount % ALIGNMENT_SIZE)) % ALIGNMENT_SIZE;
// This will cause us to stop writing to the file.
// The file will still remain open until shutdown so that we don't
// have to take a lock at this level when we touch the file stream.
m_writeErrorEncountered = (length != outCount) || !fSuccess;
-
-#ifdef _DEBUG
- _ASSERTE(m_writeErrorEncountered || (prevPos < m_currentPos));
-#endif
}
EX_CATCH
{
diff --git a/src/vm/fastserializer.h b/src/vm/fastserializer.h
index f62bb62b52..aa0501f0ae 100644
--- a/src/vm/fastserializer.h
+++ b/src/vm/fastserializer.h
@@ -86,10 +86,10 @@ public:
void WriteTag(FastSerializerTags tag, BYTE *payload = NULL, unsigned int payloadLength = 0);
void WriteString(const char *strContents, unsigned int length);
- size_t GetCurrentPosition() const
+ unsigned int GetRequiredPadding() const
{
LIMITED_METHOD_CONTRACT;
- return m_currentPos;
+ return m_requiredPadding;
}
bool HasWriteErrors() const
@@ -104,7 +104,7 @@ private:
StreamWriter *const m_pStreamWriter;
bool m_writeErrorEncountered;
- size_t m_currentPos;
+ unsigned int m_requiredPadding;
};
#endif // FEATURE_PERFTRACING