Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit584beaa

Browse files
joyeecheungmarco-ippolito
authored andcommitted
src: zero-initialize data that are copied into the snapshot
To prevent padding from making the snapshot unreproducible,zero-initialize the data that are copied into the snapshotso that the padding copied are all zeros. This is betterthan enlarging the enums to align the fields since it doesn'tmake the snapshot bigger than necessary, and it removes theneed of using static assertions to ensure alignment.PR-URL:#53563Refs:#50983Reviewed-By: Chengzhong Wu <legendecas@gmail.com>Reviewed-By: Tobias Nießen <tniessen@tnie.de>Reviewed-By: Richard Lau <rlau@redhat.com>Reviewed-By: Daniel Lemire <daniel@lemire.me>Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent229f7f8 commit584beaa

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

‎src/node_snapshotable.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1357,9 +1357,11 @@ StartupData SerializeNodeContextInternalFields(Local<Object> holder,
13571357
// To serialize the type field, save data in a EmbedderTypeInfo.
13581358
if (index == BaseObject::kEmbedderType) {
13591359
int size =sizeof(EmbedderTypeInfo);
1360-
char* data =newchar[size];
13611360
// We need to use placement new because V8 calls delete[] on the returned
13621361
// data.
1362+
// The () syntax at the end would zero-initialize the block and make
1363+
// the padding reproducible.
1364+
char* data =newchar[size]();
13631365
// TODO(joyeecheung): support cppgc objects.
13641366
new (data)EmbedderTypeInfo(obj->type(),
13651367
EmbedderTypeInfo::MemoryMode::kBaseObject);

‎src/node_snapshotable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct InternalFieldInfoBase {
4747
std::is_same_v<InternalFieldInfoBase, T>,
4848
"Can only accept InternalFieldInfoBase subclasses");
4949
void* buf = ::operatornew[](sizeof(T));
50+
memset(buf,0,sizeof(T));// Make the padding reproducible.
5051
T* result =new (buf) T;
5152
result->type = type;
5253
result->length =sizeof(T);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp