Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undefined behaviour in visual server as reported by ubsan/asan. #51266

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions servers/visual_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1429,8 +1429,10 @@ Array VisualServer::_get_array_from_surface(uint32_t p_format, PoolVector<uint8_
PoolVector<Vector3>::Write w = arr_3d.write();

for (int j = 0; j < p_vertex_len; j++) {
const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
w[j] = Vector3(v[0], v[1], v[2]);
const float &x = r[j * total_elem_size + offsets[i]];
const float &y = r[j * total_elem_size + offsets[i] + 1];
const float &z = r[j * total_elem_size + offsets[i] + 2];
Copy link
Member

@lawnjelly lawnjelly Aug 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct given that r seems to be 8 bit?

PoolVector<uint8_t>::Read r = p_vertex_data.read();

Use brackets for precedence to make it clear, but I think this does e.g.

const float &y = r[(j * total_elem_size) + offsets[i] + 1];

The +1 is 1 byte, therefore unaligned.

Copy link
Contributor

@jordo jordo Aug 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix doesn't seem correct? Since r is a byte buffer, wouldn't you want to index?

const float &y = r[j * total_elem_size + offsets[i] + 4]
const float &z = r[j * total_elem_size + offsets[i] + 8]

w[j] = Vector3(x, y, z);
}
}

Expand Down