@@ -95,6 +95,10 @@ static void hlineResize(ET* src, int cn, int *ofst, FT* m, FT* dst, int dst_min,
95
95
}
96
96
}
97
97
}
98
+ // Avoid reading a potentially unset ofst, leading to a random memory read.
99
+ if (i >= dst_width) {
100
+ return ;
101
+ }
98
102
ET* src_last = src + cn*ofst[dst_width - 1 ];
99
103
for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point
100
104
{
@@ -126,6 +130,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 2, true, 1>
126
130
ET* px = src + ofst[i];
127
131
*(dst++) = m[0 ] * px[0 ] + m[1 ] * px[1 ];
128
132
}
133
+ // Avoid reading a potentially unset ofst, leading to a random memory read.
134
+ if (i >= dst_width) {
135
+ return ;
136
+ }
129
137
src0 = (src + ofst[dst_width - 1 ])[0 ];
130
138
for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point
131
139
{
@@ -150,6 +158,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 2, true, 2>
150
158
*(dst++) = m[0 ] * px[0 ] + m[1 ] * px[2 ];
151
159
*(dst++) = m[0 ] * px[1 ] + m[1 ] * px[3 ];
152
160
}
161
+ // Avoid reading a potentially unset ofst, leading to a random memory read.
162
+ if (i >= dst_width) {
163
+ return ;
164
+ }
153
165
src0 = (src + 2 *ofst[dst_width - 1 ])[0 ];
154
166
src1 = (src + 2 *ofst[dst_width - 1 ])[1 ];
155
167
for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point
@@ -178,6 +190,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 2, true, 3>
178
190
*(dst++) = m[0 ] * px[1 ] + m[1 ] * px[4 ];
179
191
*(dst++) = m[0 ] * px[2 ] + m[1 ] * px[5 ];
180
192
}
193
+ // Avoid reading a potentially unset ofst, leading to a random memory read.
194
+ if (i >= dst_width) {
195
+ return ;
196
+ }
181
197
src0 = (src + 3 *ofst[dst_width - 1 ])[0 ];
182
198
src1 = (src + 3 *ofst[dst_width - 1 ])[1 ];
183
199
src2 = (src + 3 *ofst[dst_width - 1 ])[2 ];
@@ -210,6 +226,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 2, true, 4>
210
226
*(dst++) = m[0 ] * px[2 ] + m[1 ] * px[6 ];
211
227
*(dst++) = m[0 ] * px[3 ] + m[1 ] * px[7 ];
212
228
}
229
+ // Avoid reading a potentially unset ofst, leading to a random memory read.
230
+ if (i >= dst_width) {
231
+ return ;
232
+ }
213
233
src0 = (src + 4 *ofst[dst_width - 1 ])[0 ];
214
234
src1 = (src + 4 *ofst[dst_width - 1 ])[1 ];
215
235
src2 = (src + 4 *ofst[dst_width - 1 ])[2 ];
@@ -238,6 +258,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 4, true, 1>
238
258
ET* px = src + ofst[i];
239
259
*(dst++) = m[0 ] * src[0 ] + m[1 ] * src[1 ] + m[2 ] * src[2 ] + m[3 ] * src[3 ];
240
260
}
261
+ // Avoid reading a potentially unset ofst, leading to a random memory read.
262
+ if (i >= dst_width) {
263
+ return ;
264
+ }
241
265
src0 = (src + ofst[dst_width - 1 ])[0 ];
242
266
for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point
243
267
{
@@ -262,6 +286,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 4, true, 2>
262
286
*(dst++) = m[0 ] * src[0 ] + m[1 ] * src[2 ] + m[2 ] * src[4 ] + m[3 ] * src[6 ];
263
287
*(dst++) = m[0 ] * src[1 ] + m[1 ] * src[3 ] + m[2 ] * src[5 ] + m[3 ] * src[7 ];
264
288
}
289
+ // Avoid reading a potentially unset ofst, leading to a random memory read.
290
+ if (i >= dst_width) {
291
+ return ;
292
+ }
265
293
src0 = (src + 2 *ofst[dst_width - 1 ])[0 ];
266
294
src1 = (src + 2 *ofst[dst_width - 1 ])[1 ];
267
295
for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point
@@ -290,6 +318,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 4, true, 3>
290
318
*(dst++) = m[0 ] * src[1 ] + m[1 ] * src[4 ] + m[2 ] * src[7 ] + m[3 ] * src[10 ];
291
319
*(dst++) = m[0 ] * src[2 ] + m[1 ] * src[5 ] + m[2 ] * src[8 ] + m[3 ] * src[11 ];
292
320
}
321
+ // Avoid reading a potentially unset ofst, leading to a random memory read.
322
+ if (i >= dst_width) {
323
+ return ;
324
+ }
293
325
src0 = (src + 3 *ofst[dst_width - 1 ])[0 ];
294
326
src1 = (src + 3 *ofst[dst_width - 1 ])[1 ];
295
327
src2 = (src + 3 *ofst[dst_width - 1 ])[2 ];
@@ -322,6 +354,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 4, true, 4>
322
354
*(dst++) = m[0 ] * src[2 ] + m[1 ] * src[6 ] + m[2 ] * src[10 ] + m[3 ] * src[14 ];
323
355
*(dst++) = m[0 ] * src[3 ] + m[1 ] * src[7 ] + m[2 ] * src[11 ] + m[3 ] * src[15 ];
324
356
}
357
+ // Avoid reading a potentially unset ofst, leading to a random memory read.
358
+ if (i >= dst_width) {
359
+ return ;
360
+ }
325
361
src0 = (src + 4 *ofst[dst_width - 1 ])[0 ];
326
362
src1 = (src + 4 *ofst[dst_width - 1 ])[1 ];
327
363
src2 = (src + 4 *ofst[dst_width - 1 ])[2 ];
@@ -383,6 +419,10 @@ void hlineResizeCn<uint8_t, ufixedpoint16, 2, true, 1>(uint8_t* src, int, int *o
383
419
uint8_t * px = src + ofst[i];
384
420
*(dst++) = m[0 ] * px[0 ] + m[1 ] * px[1 ];
385
421
}
422
+ // Avoid reading a potentially unset ofst, leading to a random memory read.
423
+ if (i >= dst_width) {
424
+ return ;
425
+ }
386
426
src_0 = (src + ofst[dst_width - 1 ])[0 ];
387
427
#if (CV_SIMD || CV_SIMD_SCALABLE)
388
428
v_src_0 = vx_setall_u16 (*((uint16_t *)&src_0));
@@ -439,6 +479,10 @@ void hlineResizeCn<uint8_t, ufixedpoint16, 2, true, 2>(uint8_t* src, int, int *o
439
479
*(dst++) = m[0 ] * px[0 ] + m[1 ] * px[2 ];
440
480
*(dst++) = m[0 ] * px[1 ] + m[1 ] * px[3 ];
441
481
}
482
+ // Avoid reading a potentially unset ofst, leading to a random memory read.
483
+ if (i >= dst_width) {
484
+ return ;
485
+ }
442
486
((ufixedpoint16*)(srccn.w ))[0 ] = (src + 2 * ofst[dst_width - 1 ])[0 ]; ((ufixedpoint16*)(srccn.w ))[1 ] = (src + 2 * ofst[dst_width - 1 ])[1 ];
443
487
#if (CV_SIMD || CV_SIMD_SCALABLE)
444
488
v_srccn = v_reinterpret_as_u16 (vx_setall_u32 (srccn.d ));
@@ -511,6 +555,10 @@ void hlineResizeCn<uint8_t, ufixedpoint16, 2, true, 3>(uint8_t* src, int, int *o
511
555
*(dst++) = m[0 ] * px[1 ] + m[1 ] * px[4 ];
512
556
*(dst++) = m[0 ] * px[2 ] + m[1 ] * px[5 ];
513
557
}
558
+ // Avoid reading a potentially unset ofst, leading to a random memory read.
559
+ if (i >= dst_width) {
560
+ return ;
561
+ }
514
562
((ufixedpoint16*)(srccn.w ))[0 ] = (src + 3 *ofst[dst_width - 1 ])[0 ];
515
563
((ufixedpoint16*)(srccn.w ))[1 ] = (src + 3 *ofst[dst_width - 1 ])[1 ];
516
564
((ufixedpoint16*)(srccn.w ))[2 ] = (src + 3 *ofst[dst_width - 1 ])[2 ];
@@ -584,6 +632,10 @@ void hlineResizeCn<uint8_t, ufixedpoint16, 2, true, 4>(uint8_t* src, int, int *o
584
632
*(dst++) = m[0 ] * px[2 ] + m[1 ] * px[6 ];
585
633
*(dst++) = m[0 ] * px[3 ] + m[1 ] * px[7 ];
586
634
}
635
+ // Avoid reading a potentially unset ofst, leading to a random memory read.
636
+ if (i >= dst_width) {
637
+ return ;
638
+ }
587
639
((ufixedpoint16*)(srccn.w ))[0 ] = (src + 4 * ofst[dst_width - 1 ])[0 ]; ((ufixedpoint16*)(srccn.w ))[1 ] = (src + 4 * ofst[dst_width - 1 ])[1 ];
588
640
((ufixedpoint16*)(srccn.w ))[2 ] = (src + 4 * ofst[dst_width - 1 ])[2 ]; ((ufixedpoint16*)(srccn.w ))[3 ] = (src + 4 * ofst[dst_width - 1 ])[3 ];
589
641
#if (CV_SIMD || CV_SIMD_SCALABLE)
@@ -635,6 +687,10 @@ void hlineResizeCn<uint16_t, ufixedpoint32, 2, true, 1>(uint16_t* src, int, int
635
687
uint16_t * px = src + ofst[i];
636
688
*(dst++) = m[0 ] * px[0 ] + m[1 ] * px[1 ];
637
689
}
690
+ // Avoid reading a potentially unset ofst, leading to a random memory read.
691
+ if (i >= dst_width) {
692
+ return ;
693
+ }
638
694
src_0 = (src + ofst[dst_width - 1 ])[0 ];
639
695
#if (CV_SIMD || CV_SIMD_SCALABLE)
640
696
v_src_0 = vx_setall_u32 (*((uint32_t *)&src_0));
0 commit comments