Skip to content

Commit fecd5e5

Browse files
committed
Limit frame buffer size to protect it from overflow
1 parent 48491ac commit fecd5e5

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;
@@ -163,6 +168,13 @@ class SubtitleOctopus {
163168

164169
/* CANVAS */
165170
void resizeCanvas(int frame_w, int frame_h) {
171+
if (frame_w > FRAMEBUFFER_MAX_WIDTH || frame_h > FRAMEBUFFER_MAX_HEIGHT) {
172+
fprintf(stderr, "jso: canvas is oversized - %dx%d\n", frame_w, frame_h);
173+
if (frame_w > FRAMEBUFFER_MAX_WIDTH) frame_w = FRAMEBUFFER_MAX_WIDTH;
174+
if (frame_h > FRAMEBUFFER_MAX_HEIGHT) frame_h = FRAMEBUFFER_MAX_HEIGHT;
175+
printf("jso: canvas is trimmed to %dx%d\n", frame_w, frame_h);
176+
}
177+
166178
ass_set_frame_size(ass_renderer, frame_w, frame_h);
167179
canvas_h = frame_h;
168180
canvas_w = frame_w;

0 commit comments

Comments
 (0)