From 0532e36c165481134788c89d58c84392d613a9bf Mon Sep 17 00:00:00 2001
From: Alexander Strasser <eclipse7@gmx.net>
Date: Tue, 29 Sep 2026 23:36:19 +0200
Subject: [PATCH v1] WIP: XXX: spudec_process_control: Don't read beyond packet
boundary
Tickets: #2432
---
sub/spudec.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/sub/spudec.c b/sub/spudec.c
index 516ce52e6..7ad60e7e6 100644
|
a
|
b
|
static void spudec_process_control(spudec_handle_t *this, int pts100)
|
| 463 | 463 | unsigned int height = 0; |
| 464 | 464 | unsigned int stride = 0; |
| 465 | 465 | |
| | 466 | if (this->packet_size < 4) { |
| | 467 | return; |
| | 468 | } |
| 466 | 469 | control_start = get_be16(this->packet + 2); |
| 467 | 470 | next_off = control_start; |
| 468 | 471 | while (start_off != next_off) { |
| | 472 | if (next_off >= this->packet_size - 3) { |
| | 473 | return; |
| | 474 | } |
| 469 | 475 | start_off = next_off; |
| 470 | 476 | date = get_be16(this->packet + start_off) * 1024; |
| 471 | 477 | next_off = get_be16(this->packet + start_off + 2); |
| 472 | 478 | mp_msg(MSGT_SPUDEC,MSGL_DBG2, "date=%d\n", date); |
| 473 | 479 | off = start_off + 4; |
| 474 | | for (type = this->packet[off++]; type != 0xff; type = this->packet[off++]) { |
| | 480 | for (type = this->packet[off++]; off <= this->packet_size && type != 0xff; type = this->packet[off++]) { |
| 475 | 481 | mp_msg(MSGT_SPUDEC,MSGL_DBG2, "cmd=%d ",type); |
| 476 | 482 | switch(type) { |
| 477 | 483 | case 0x00: |
| … |
… |
static void spudec_process_control(spudec_handle_t *this, int pts100)
|
| 498 | 504 | break; |
| 499 | 505 | case 0x03: |
| 500 | 506 | /* Palette */ |
| | 507 | if (off >= this->packet_size - 1) { |
| | 508 | return; |
| | 509 | } |
| 501 | 510 | this->palette[0] = this->packet[off] >> 4; |
| 502 | 511 | this->palette[1] = this->packet[off] & 0xf; |
| 503 | 512 | this->palette[2] = this->packet[off + 1] >> 4; |
| … |
… |
static void spudec_process_control(spudec_handle_t *this, int pts100)
|
| 508 | 517 | break; |
| 509 | 518 | case 0x04: |
| 510 | 519 | /* Alpha */ |
| | 520 | if (off >= this->packet_size - 1) { |
| | 521 | return; |
| | 522 | } |
| 511 | 523 | a = this->packet[off] >> 4; |
| 512 | 524 | b = this->packet[off] & 0xf; |
| 513 | 525 | c = this->packet[off + 1] >> 4; |
| … |
… |
static void spudec_process_control(spudec_handle_t *this, int pts100)
|
| 530 | 542 | break; |
| 531 | 543 | case 0x05: |
| 532 | 544 | /* Co-ords */ |
| | 545 | if (off >= this->packet_size - 5) { |
| | 546 | return; |
| | 547 | } |
| 533 | 548 | a = get_be24(this->packet + off); |
| 534 | 549 | b = get_be24(this->packet + off + 3); |
| 535 | 550 | start_col = a >> 12; |
| … |
… |
static void spudec_process_control(spudec_handle_t *this, int pts100)
|
| 546 | 561 | break; |
| 547 | 562 | case 0x06: |
| 548 | 563 | /* Graphic lines */ |
| | 564 | if (off >= this->packet_size - 3) { |
| | 565 | return; |
| | 566 | } |
| 549 | 567 | current_nibble[0] = 2 * get_be16(this->packet + off); |
| 550 | 568 | current_nibble[1] = 2 * get_be16(this->packet + off + 2); |
| 551 | 569 | mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Graphic offset 1: %d offset 2: %d\n", |