Skip to content

Commit 5383774

Browse files
committed
Limit frame buffer size to protect it from overflow
1 parent f608baa commit 5383774

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/SubtitleOctopus.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919

2020
int log_level = 3;
2121

22+
// maximum frame buffer width (8K resolution)
23+
const size_t FRAMEBUFFER_MAX_WIDTH = 7680;
24+
// maximum frame buffer height (8K resolution)
25+
const size_t FRAMEBUFFER_MAX_HEIGHT = 4320;
26+
2227
typedef struct {
2328
void *buffer;
2429
size_t size;
@@ -159,6 +164,13 @@ class SubtitleOctopus {
159164

160165
/* CANVAS */
161166
void resizeCanvas(int frame_w, int frame_h) {
167+
if (frame_w > FRAMEBUFFER_MAX_WIDTH || frame_h > FRAMEBUFFER_MAX_HEIGHT) {
168+
fprintf(stderr, "libass: canvas is oversized - %dx%d\n", frame_w, frame_h);
169+
if (frame_w > FRAMEBUFFER_MAX_WIDTH) frame_w = FRAMEBUFFER_MAX_WIDTH;
170+
if (frame_h > FRAMEBUFFER_MAX_HEIGHT) frame_h = FRAMEBUFFER_MAX_HEIGHT;
171+
printf("libass: canvas is trimmed to %dx%d\n", frame_w, frame_h);
172+
}
173+
162174
ass_set_frame_size(ass_renderer, frame_w, frame_h);
163175
canvas_h = frame_h;
164176
canvas_w = frame_w;

0 commit comments

Comments
 (0)