History

draw_bmp: fix overflowing coordinates in mark_rcs

This is yet another unfortunate side effect of the width % SLICE_W == 0 special case. While looping through these rectangles, the rc->x1 value on the final loop can be greater than the actual total width. This will cause a buffer overflow if using the mp_draw_sub_overlay API. 2 of the current VOs that use that work around it by adjusting the values returned, but the better fix is to correct what's actually given in the rectangles so you can safely use the values. As for the fix, it's simply ensuring that rc->x1 doesn't extend beyond p->w with a MPCLAMP. Previously, the code would always naively add SLICE_W (256) to rc->x0 which would easily extend past the actual width in many cases. The adjustments in vo_vaapi and vo_dmabuf_wayland are dropped and in theory vo_direct3d should work now since we can just trust the values given to us in the rectangles. How nice.

Dudemanguy committed 3 years ago

Commit b7bf5e61 parent 16080593 files · +2 −9Browse files

Unified · Split

3 files
  1. sub/draw_bmp.c +2 −1
  2. video/out/vo_dmabuf_wayland.c +0 −4
  3. video/out/vo_vaapi.c +0 −4
sub/draw_bmp.c+2−1
@@ -968,7 +968,8 @@ static void mark_rcs(struct mp_draw_sub_cache *p, struct rc_grid *gr) · 967 unmodified lines
968968 rc->y0 = MPMIN(rc->y0, y);
969969 rc->y1 = MPMAX(rc->y1, y + 1);
970970 rc->x0 = MPMIN(rc->x0, xpos + s->x0);
971− rc->x1 = MPMAX(rc->x1, xpos + s->x1);
971+ // Ensure this does not extend beyond the total width
972+ rc->x1 = MPCLAMP(xpos + s->x1, rc->x1, p->w);
972973 }
973974 }
974975 }
video/out/vo_dmabuf_wayland.c+0−4
@@ -565,10 +565,6 @@ static bool draw_osd(struct vo *vo, struct mp_image *cur, double pts) · 564 unmodified lines
565565 void *src = mp_image_pixel_ptr(osd, 0, rc.x0, rc.y0);
566566 void *dst = cur->planes[0] + rc.x0 * 4 + rc.y0 * cur->stride[0];
567567
568− // Avoid overflowing if we have this special case.
569− if (n == num_mod_rc - 1)
570− --rh;
571−
572568 memcpy_pic(dst, src, rw * 4, rh, cur->stride[0], osd->stride[0]);
573569 }
574570
video/out/vo_vaapi.c+0−4
@@ -684,10 +684,6 @@ static void draw_osd(struct vo *vo) · 683 unmodified lines
684684 int rw = mp_rect_w(*rc);
685685 int rh = mp_rect_h(*rc);
686686
687− // reduce width of last slice to prevent overflow
688− if (n == num_mod_rc - 1)
689− rw = w - rc->x0;
690−
691687 void *src = mp_image_pixel_ptr(osd, 0, rc->x0, rc->y0);
692688 void *dst = vaimg.planes[0] + rc->y0 * vaimg.stride[0] + rc->x0 * 4;
693689

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t