comparison src/audio/sdlgenaudiocvt.pl @ 3602:bfa8d34ce03a

Fixed buffer overflows in resamplers. I'm not confident this is a complete fix, but I'm not confident the current resamplers are really worth keeping at all, either.
author Ryan C. Gordon <icculus@icculus.org>
date Mon, 28 Dec 2009 08:28:24 +0000
parents 77c3e67f0740
children 8c9cbb623d55
comparison
equal deleted inserted replaced
3601:240a7700a271 3602:bfa8d34ce03a
535 535
536 const int srcsize = cvt->len_cvt; 536 const int srcsize = cvt->len_cvt;
537 const int dstsize = cvt->len_cvt $lencvtop $multiple; 537 const int dstsize = cvt->len_cvt $lencvtop $multiple;
538 EOF 538 EOF
539 539
540 my $endcomparison = '!=';
541
540 # Upsampling (growing the buffer) needs to work backwards, since we 542 # Upsampling (growing the buffer) needs to work backwards, since we
541 # overwrite the buffer as we go. 543 # overwrite the buffer as we go.
542 if ($upsample) { 544 if ($upsample) {
545 $endcomparison = '>'; # dst > target
543 print <<EOF; 546 print <<EOF;
544 $fctype *dst = (($fctype *) (cvt->buf + dstsize)) - $channels; 547 $fctype *dst = (($fctype *) (cvt->buf + dstsize)) - $channels;
545 const $fctype *src = (($fctype *) (cvt->buf + cvt->len_cvt)) - $channels; 548 const $fctype *src = (($fctype *) (cvt->buf + cvt->len_cvt)) - $channels;
546 const $fctype *target = ((const $fctype *) cvt->buf) - $channels; 549 const $fctype *target = ((const $fctype *) cvt->buf) - $channels;
547 EOF 550 EOF
548 } else { 551 } else {
552 $endcomparison = '<'; # dst < target
549 print <<EOF; 553 print <<EOF;
550 $fctype *dst = ($fctype *) cvt->buf; 554 $fctype *dst = ($fctype *) cvt->buf;
551 const $fctype *src = ($fctype *) cvt->buf; 555 const $fctype *src = ($fctype *) cvt->buf;
552 const $fctype *target = (const $fctype *) (cvt->buf + dstsize); 556 const $fctype *target = (const $fctype *) (cvt->buf + dstsize);
553 EOF 557 EOF
560 $bigger last_sample${idx} = ($bigger) $val; 564 $bigger last_sample${idx} = ($bigger) $val;
561 EOF 565 EOF
562 } 566 }
563 567
564 print <<EOF; 568 print <<EOF;
565 while (dst != target) { 569 while (dst $endcomparison target) {
566 EOF 570 EOF
567 571
568 for (my $i = 0; $i < $channels; $i++) { 572 for (my $i = 0; $i < $channels; $i++) {
569 my $idx = ($upsample) ? (($channels - $i) - 1) : $i; 573 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
570 my $val = getSwapFunc($fsize, $fsigned, $ffloat, $fendian, "src[$idx]"); 574 my $val = getSwapFunc($fsize, $fsigned, $ffloat, $fendian, "src[$idx]");