mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-28 02:11:43 +00:00
[wpiutil] MemoryBuffer: Fix GetMemoryBufferForStream (#5017)
This would previously just write past the end of the buffer, smashing the stack. It's only called in the case when a non-file or block device is used as the file.
This commit is contained in:
@@ -237,14 +237,17 @@ static std::unique_ptr<WritableMemoryBuffer> GetMemoryBufferForStream(
|
||||
#endif
|
||||
// Read into Buffer until we hit EOF.
|
||||
do {
|
||||
buffer.resize_for_overwrite(buffer.size() + ChunkSize);
|
||||
size_t prevSize = buffer.size();
|
||||
buffer.resize_for_overwrite(prevSize + ChunkSize);
|
||||
#ifdef _WIN32
|
||||
if (!ReadFile(f, buffer.end(), ChunkSize, &readBytes, nullptr)) {
|
||||
if (!ReadFile(f, buffer.begin() + prevSize, ChunkSize, &readBytes,
|
||||
nullptr)) {
|
||||
ec = mapWindowsError(GetLastError());
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
readBytes = sys::RetryAfterSignal(-1, ::read, f, buffer.end(), ChunkSize);
|
||||
readBytes = sys::RetryAfterSignal(-1, ::read, f, buffer.begin() + prevSize,
|
||||
ChunkSize);
|
||||
if (readBytes == -1) {
|
||||
ec = std::error_code(errno, std::generic_category());
|
||||
return nullptr;
|
||||
|
||||
Reference in New Issue
Block a user