Skip to content

Commit 7c9f7f4

Browse files
sstricklcommit-bot@chromium.org
authored andcommitted
[vm/aot] Fix UB behavior due to WriteFixed usage at unaligned positions.
Change-Id: Icc4f05bbec03aee1f60c690e3bef8b5f6f159470 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150933 Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Tess Strickland <[email protected]>
1 parent f043f9e commit 7c9f7f4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

runtime/vm/elf.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -881,9 +881,10 @@ class DwarfElfStream : public DwarfWriteStream {
881881
}
882882

883883
void u1(uint8_t value) { stream_->WriteFixed(value); }
884-
void u2(uint16_t value) { stream_->WriteFixed(value); }
885-
void u4(uint32_t value) { stream_->WriteFixed(value); }
886-
void u8(uint64_t value) { stream_->WriteFixed(value); }
884+
// Can't use WriteFixed for these, as we may not be at aligned positions.
885+
void u2(uint16_t value) { stream_->WriteBytes(&value, sizeof(value)); }
886+
void u4(uint32_t value) { stream_->WriteBytes(&value, sizeof(value)); }
887+
void u8(uint64_t value) { stream_->WriteBytes(&value, sizeof(value)); }
887888
void string(const char* cstr) { // NOLINT
888889
stream_->WriteBytes(reinterpret_cast<const uint8_t*>(cstr),
889890
strlen(cstr) + 1);

0 commit comments

Comments
 (0)