Skip to content

Commit d6263ea

Browse files
committed
Add some sanity checks
1 parent 38f27d9 commit d6263ea

1 file changed

Lines changed: 48 additions & 9 deletions

File tree

descale.cpp

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/*
22
* Copyright © 2017 Frechdachs <frechdachs@rekt.cc>
3-
* This work is free. You can redistribute it and/or modify it under the
4-
* terms of the Do What The Fuck You Want To Public License, Version 2,
5-
* as published by Sam Hocevar. See the COPYING file for more details.
3+
* This program is free software. It comes without any warranty, to
4+
* the extent permitted by applicable law. You can redistribute it
5+
* and/or modify it under the terms of the Do What The Fuck You Want
6+
* To Public License, Version 2, as published by Sam Hocevar.
7+
* See the COPYING file for more details.
68
*/
79

810

@@ -100,7 +102,8 @@ void multiply_banded_matrix_with_diagonal(int rows, int bandwidth, std::vector<d
100102

101103
// LDLT decomposition (variant of Cholesky decomposition)
102104
// Input is only the upper part of a banded symmetrical matrix in compressed form.
103-
// The input matrix is modified in-place and equals L' in compressed form after decomposition.
105+
// The input matrix is modified in-place and contains L' and D in compressed form
106+
// after decomposition. The main diagonal of ones of L' is not saved.
104107
void banded_ldlt_decomposition(int rows, int bandwidth, std::vector<double> &matrix)
105108
{
106109
int c = (bandwidth + 1) / 2;
@@ -645,8 +648,14 @@ static void VS_CC debilinear_create(const VSMap *in, VSMap *out, void *userData,
645648
if (err)
646649
d.shift_v = 0;
647650

651+
if (d.width < 1 || d.height < 1) {
652+
vsapi->setError(out, "Descale: width and height must be bigger than 0.");
653+
vsapi->freeNode(d.node);
654+
return;
655+
}
656+
648657
if (d.width > d.vi->width || d.height > d.vi->height) {
649-
vsapi->setError(out, "Descale: Output dimension has to be smaller or equal to input dimension.");
658+
vsapi->setError(out, "Descale: Output dimension has to be smaller than or equal to input dimension.");
650659
vsapi->freeNode(d.node);
651660
return;
652661
}
@@ -712,8 +721,14 @@ static void VS_CC debicubic_create(const VSMap *in, VSMap *out, void *userData,
712721
if (err)
713722
d.shift_v = 0;
714723

724+
if (d.width < 1 || d.height < 1) {
725+
vsapi->setError(out, "Descale: width and height must be bigger than 0.");
726+
vsapi->freeNode(d.node);
727+
return;
728+
}
729+
715730
if (d.width > d.vi->width || d.height > d.vi->height) {
716-
vsapi->setError(out, "Descale: Output dimension has to be smaller or equal to input dimension.");
731+
vsapi->setError(out, "Descale: Output dimension has to be smaller than or equal to input dimension.");
717732
vsapi->freeNode(d.node);
718733
return;
719734
}
@@ -775,8 +790,20 @@ static void VS_CC delanczos_create(const VSMap *in, VSMap *out, void *userData,
775790
if (err)
776791
d.shift_v = 0;
777792

793+
if (d.width < 1 || d.height < 1) {
794+
vsapi->setError(out, "Descale: width and height must be bigger than 0.");
795+
vsapi->freeNode(d.node);
796+
return;
797+
}
798+
778799
if (d.width > d.vi->width || d.height > d.vi->height) {
779-
vsapi->setError(out, "Descale: Output dimension has to be smaller or equal to input dimension.");
800+
vsapi->setError(out, "Descale: Output dimension has to be smaller than or equal to input dimension.");
801+
vsapi->freeNode(d.node);
802+
return;
803+
}
804+
805+
if (d.taps < 1) {
806+
vsapi->setError(out, "Descale: taps must be bigger than 0.");
780807
vsapi->freeNode(d.node);
781808
return;
782809
}
@@ -834,8 +861,14 @@ static void VS_CC despline16_create(const VSMap *in, VSMap *out, void *userData,
834861
if (err)
835862
d.shift_v = 0;
836863

864+
if (d.width < 1 || d.height < 1) {
865+
vsapi->setError(out, "Descale: width and height must be bigger than 0.");
866+
vsapi->freeNode(d.node);
867+
return;
868+
}
869+
837870
if (d.width > d.vi->width || d.height > d.vi->height) {
838-
vsapi->setError(out, "Descale: Output dimension has to be smaller or equal to input dimension.");
871+
vsapi->setError(out, "Descale: Output dimension has to be smaller than or equal to input dimension.");
839872
vsapi->freeNode(d.node);
840873
return;
841874
}
@@ -893,8 +926,14 @@ static void VS_CC despline36_create(const VSMap *in, VSMap *out, void *userData,
893926
if (err)
894927
d.shift_v = 0;
895928

929+
if (d.width < 1 || d.height < 1) {
930+
vsapi->setError(out, "Descale: width and height must be bigger than 0.");
931+
vsapi->freeNode(d.node);
932+
return;
933+
}
934+
896935
if (d.width > d.vi->width || d.height > d.vi->height) {
897-
vsapi->setError(out, "Descale: Output dimension has to be smaller or equal to input dimension.");
936+
vsapi->setError(out, "Descale: Output dimension has to be smaller than or equal to input dimension.");
898937
vsapi->freeNode(d.node);
899938
return;
900939
}

0 commit comments

Comments
 (0)