Skip to content

Commit

Permalink
Merge pull request #1157 from ray1422/master
Browse files Browse the repository at this point in the history
Fix misaligned dereference in H264 and H265 packetizers
  • Loading branch information
paullouisageneau authored Apr 15, 2024
2 parents d69d52e + 9e3871b commit 6e45f8f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 4 additions & 1 deletion examples/streamer/h264fileparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "rtc/rtc.hpp"

#include <fstream>
#include <cstring>

#ifdef _WIN32
#include <winsock2.h>
Expand All @@ -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());
Expand Down
5 changes: 3 additions & 2 deletions src/h264rtppacketizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 3 additions & 2 deletions src/h265rtppacketizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ shared_ptr<H265NalUnits> H265RtpPacketizer::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;

Expand Down

0 comments on commit 6e45f8f

Please sign in to comment.