[libbluray-devel] [Git][videolan/libbluray][master] 2 commits: _decode_rle(): end runs with their line
Petri Hintukainen (@hpi)
gitlab at videolan.org
Sat Nov 21 13:06:31 UTC 2026
Petri Hintukainen pushed to branch master at VideoLAN / libbluray
Commits:
ad31fd1f by Kacper Michajłow at 2026-11-20T13:45:47+01:00
_decode_rle(): end runs with their line
Only the sum of the runs was checked against the object size, while
rle_crop_object() and applications read the image line by line. A run
that crossed a line end made them read past the end of the image.
Split such runs and store an EOL marker after every line. Images of
conforming objects do not change.
- - - - -
6ce447b7 by Kacper Michajłow at 2026-11-20T13:46:31+01:00
graphics_controller: check the cropping rectangle of composition objects
The rectangle was used as it came from the stream. One that is not
inside the object made rle_crop_object() read past the end of the image,
or passed the application an image with fewer lines than the height
given with it. Do not render such a composition object. Also ignore
empty rectangle.
- - - - -
2 changed files:
- src/libbluray/decoders/graphics_controller.c
- src/libbluray/decoders/pg_decode.c
Changes:
=====================================
src/libbluray/decoders/graphics_controller.c
=====================================
@@ -617,6 +617,15 @@ static void _render_composition_object(GRAPHICS_CONTROLLER *gc,
ov.img = object->img;
if (cobj->crop_flag) {
+ if (cobj->crop_x + cobj->crop_w > object->width ||
+ cobj->crop_y + cobj->crop_h > object->height) {
+ GC_ERROR("_render_composition_object: cropping rectangle outside of object #%d\n",
+ object->id);
+ return;
+ }
+ if (!cobj->crop_w || !cobj->crop_h) {
+ return;
+ }
if (cobj->crop_x || cobj->crop_y || cobj->crop_w != object->width) {
cropped_img = rle_crop_object(object->img, object->width,
cobj->crop_x, cobj->crop_y, cobj->crop_w, cobj->crop_h);
=====================================
src/libbluray/decoders/pg_decode.c
=====================================
@@ -120,12 +120,34 @@ int pg_decode_palette(BITBUFFER *bb, BD_PG_PALETTE *p)
return pg_decode_palette_update(bb, p);
}
+static int _add_rle(BD_PG_OBJECT *p, int *num_rle, int *rle_size, uint16_t len, uint16_t color)
+{
+ BD_PG_RLE_ELEM *tmp;
+
+ p->img[*num_rle].len = len;
+ p->img[*num_rle].color = color;
+
+ (*num_rle)++;
+ if (*num_rle >= *rle_size) {
+ *rle_size *= 2;
+ tmp = refcnt_realloc(p->img, *rle_size * sizeof(BD_PG_RLE_ELEM), NULL);
+ if (!tmp) {
+ BD_DEBUG(DBG_DECODE | DBG_CRIT, "pg_decode_object(): realloc failed\n");
+ return 0;
+ }
+ p->img = tmp;
+ }
+
+ return 1;
+}
+
static int _decode_rle(BITBUFFER *bb, BD_PG_OBJECT *p)
{
BD_PG_RLE_ELEM *tmp;
int64_t pixels_left = (int64_t)p->width * p->height;
int rle_size = (int)(pixels_left / 4);
int num_rle = 0;
+ unsigned x = 0;
if (rle_size < 1)
rle_size = 1;
@@ -161,9 +183,6 @@ static int _decode_rle(BITBUFFER *bb, BD_PG_OBJECT *p)
}
}
- p->img[num_rle].len = len;
- p->img[num_rle].color = color;
-
pixels_left -= len;
if (pixels_left < 0) {
@@ -171,15 +190,21 @@ static int _decode_rle(BITBUFFER *bb, BD_PG_OBJECT *p)
return 0;
}
- num_rle++;
- if (num_rle >= rle_size) {
- rle_size *= 2;
- tmp = refcnt_realloc(p->img, rle_size * sizeof(BD_PG_RLE_ELEM), NULL);
- if (!tmp) {
- BD_DEBUG(DBG_DECODE | DBG_CRIT, "pg_decode_object(): realloc failed\n");
+ while (len > 0) {
+ uint32_t run = BD_MIN(len, p->width - x);
+
+ if (!_add_rle(p, &num_rle, &rle_size, run, color)) {
return 0;
}
- p->img = tmp;
+ len -= run;
+ x += run;
+
+ if (x == p->width) {
+ if (!_add_rle(p, &num_rle, &rle_size, 0, 0)) {
+ return 0;
+ }
+ x = 0;
+ }
}
}
View it on GitLab: https://code.videolan.org/videolan/libbluray/-/compare/4613535451af402c6d72665e8cd88be1b29c9158...6ce447b7b8aca01f3528b6bd4225b11e486fe77e
--
View it on GitLab: https://code.videolan.org/videolan/libbluray/-/compare/4613535451af402c6d72665e8cd88be1b29c9158...6ce447b7b8aca01f3528b6bd4225b11e486fe77e
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help
More information about the libbluray-devel
mailing list