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 misaligned dereference in H264 and H265 packetizers #1157

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Changes from 1 commit
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
Next Next commit
Fix misaligned dereference in H264 Parser
Use memcpy instead of direct dereference to avoid
misaligned access.
Ray Chung authored and Ray Chung committed Apr 10, 2024
commit 82f996246809f4a3e86c9a693a0731f6738012f9
5 changes: 4 additions & 1 deletion examples/streamer/h264fileparser.cpp
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
#include "rtc/rtc.hpp"

#include <fstream>
#include <cstring>

#ifdef _WIN32
#include <winsock2.h>
@@ -29,7 +30,9 @@ void H264FileParser::loadNextSample() {
while (i < sample.size()) {
assert(i + 4 < sample.size());
auto lengthPtr = (uint32_t *) (sample.data() + i);
uint32_t length = ntohl(*lengthPtr);
uint32_t length;
std::memcpy(&length, lengthPtr, sizeof(uint32_t));
length = ntohl(length);
auto naluStartIndex = i + 4;
auto naluEndIndex = naluStartIndex + length;
assert(naluEndIndex <= sample.size());
5 changes: 3 additions & 2 deletions src/h264rtppacketizer.cpp
Original file line number Diff line number Diff line change
@@ -32,8 +32,9 @@ shared_ptr<NalUnits> H264RtpPacketizer::splitMessage(binary_ptr message) {
LOG_WARNING << "Invalid NAL Unit data (incomplete length), ignoring!";
break;
}
auto lengthPtr = (uint32_t *)(message->data() + index);
uint32_t length = ntohl(*lengthPtr);
uint32_t length;
std::memcpy(&length, message->data() + index, sizeof(uint32_t));
length = ntohl(length);
auto naluStartIndex = index + 4;
auto naluEndIndex = naluStartIndex + length;