mirror of
https://gitee.com/xia-chu/ZLMediaKit.git
synced 2026-06-21 22:47:49 +08:00
Limit RTP/JPEG reassembly to prevent unbounded memory growth (#4764)
Some checks failed
Android / build (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docker / build (push) Has been cancelled
DockerPy / build (push) Has been cancelled
Linux / build (push) Has been cancelled
Linux_Python / build (push) Has been cancelled
macOS / build (push) Has been cancelled
macOS_Python / build (push) Has been cancelled
Windows / build (push) Has been cancelled
Windows_Python / build (push) Has been cancelled
Some checks failed
Android / build (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docker / build (push) Has been cancelled
DockerPy / build (push) Has been cancelled
Linux / build (push) Has been cancelled
Linux_Python / build (push) Has been cancelled
macOS / build (push) Has been cancelled
macOS_Python / build (push) Has been cancelled
Windows / build (push) Has been cancelled
Windows_Python / build (push) Has been cancelled
This commit is contained in:
parent
14fd9187b8
commit
5f11d3b3bf
@ -4,6 +4,11 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace mediakit;
|
using namespace mediakit;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
// Prevent unbounded memory growth from malformed/hostile RTP/JPEG streams.
|
||||||
|
constexpr size_t kMaxRtpJpegFrameSize = 16 * 1024 * 1024;
|
||||||
|
}
|
||||||
|
|
||||||
#define AV_WB24(p, d) \
|
#define AV_WB24(p, d) \
|
||||||
do { \
|
do { \
|
||||||
((uint8_t *)(p))[2] = (d); \
|
((uint8_t *)(p))[2] = (d); \
|
||||||
@ -539,6 +544,13 @@ static int jpeg_parse_packet(void *ctx, PayloadContext *jpeg, uint32_t *timestam
|
|||||||
height, qtables,
|
height, qtables,
|
||||||
qtable_len / 64, dri);
|
qtable_len / 64, dri);
|
||||||
|
|
||||||
|
if ((size_t)jpeg->hdr_size > kMaxRtpJpegFrameSize) {
|
||||||
|
jpeg->frame.clear();
|
||||||
|
av_log(ctx, AV_LOG_ERROR,
|
||||||
|
"RTP/JPEG header is too large; dropping frame.\n");
|
||||||
|
return AVERROR_INVALIDDATA;
|
||||||
|
}
|
||||||
|
|
||||||
/* Copy JPEG header to frame buffer. */
|
/* Copy JPEG header to frame buffer. */
|
||||||
avio_write(jpeg->frame, hdr, jpeg->hdr_size);
|
avio_write(jpeg->frame, hdr, jpeg->hdr_size);
|
||||||
}
|
}
|
||||||
@ -563,6 +575,13 @@ static int jpeg_parse_packet(void *ctx, PayloadContext *jpeg, uint32_t *timestam
|
|||||||
return AVERROR_EAGAIN;
|
return AVERROR_EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (jpeg->frame.size() + len + 2 > kMaxRtpJpegFrameSize) {
|
||||||
|
jpeg->frame.clear();
|
||||||
|
av_log(ctx, AV_LOG_ERROR,
|
||||||
|
"RTP/JPEG frame is too large; dropping frame.\n");
|
||||||
|
return AVERROR_INVALIDDATA;
|
||||||
|
}
|
||||||
|
|
||||||
/* Copy data to frame buffer. */
|
/* Copy data to frame buffer. */
|
||||||
avio_write(jpeg->frame, buf, len);
|
avio_write(jpeg->frame, buf, len);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user