Revert "Revised to address int overflow in for loop only"

This reverts commit e74ee84320.
This commit is contained in:
Eharve14 2022-01-13 11:35:20 -05:00
parent e74ee84320
commit d8fe12641e
3 changed files with 22 additions and 3 deletions

View File

@ -1957,6 +1957,11 @@ int main(int argc, char **argv)
/* Read directory if necessary */
if (img_fol.set_imgdir == 1) {
num_images = get_num_images(img_fol.imgdirpath);
if((num_images > SIZE_MAX/(OPJ_PATH_LEN * sizeof(char)))){
fprintf(stdout, "Max images exceeded\n");
ret = 0;
goto fin;
} else {
dirptr = (dircnt_t*)malloc(sizeof(dircnt_t));
if (dirptr) {
dirptr->filename_buf = (char*)calloc(num_images, OPJ_PATH_LEN * sizeof(
@ -1966,7 +1971,7 @@ int main(int argc, char **argv)
ret = 0;
goto fin;
}
for (size_t i = 0; i < num_images; i++) {
for (i = 0; i < num_images; i++) {
dirptr->filename[i] = dirptr->filename_buf + i * OPJ_PATH_LEN;
}
}
@ -1974,6 +1979,7 @@ int main(int argc, char **argv)
ret = 0;
goto fin;
}
}
if (num_images == 0) {
fprintf(stdout, "Folder is empty\n");
ret = 0;

View File

@ -1365,7 +1365,13 @@ int main(int argc, char **argv)
/* Initialize reading of directory */
if (img_fol.set_imgdir == 1) {
int it_image;
num_images = get_num_images(img_fol.imgdirpath);
if( num_images > SIZE_MAX/(sizeof(char)* OPJ_PATH_LEN)){
fprintf(stderr, "Max number of images exceeded\n");
failed = 1;
goto fin;
} else {
dirptr = (dircnt_t*)calloc(1, sizeof(dircnt_t));
if (!dirptr) {
destroy_parameters(&parameters);
@ -1384,7 +1390,7 @@ int main(int argc, char **argv)
failed = 1;
goto fin;
}
for (size_t it_image = 0; it_image < num_images; it_image++) {
for (it_image = 0; it_image < num_images; it_image++) {
dirptr->filename[it_image] = dirptr->filename_buf + it_image * OPJ_PATH_LEN;
}
@ -1392,6 +1398,7 @@ int main(int argc, char **argv)
failed = 1;
goto fin;
}
}
if (num_images == 0) {
fprintf(stderr, "Folder is empty\n");
failed = 1;

View File

@ -508,6 +508,7 @@ int main(int argc, char *argv[])
/* Initialize reading of directory */
if (img_fol.set_imgdir == 1) {
int it_image;
num_images = get_num_images(img_fol.imgdirpath);
dirptr = (dircnt_t*)malloc(sizeof(dircnt_t));
@ -515,6 +516,10 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
/* Stores at max 10 image file names*/
if(num_images> SIZE_MAX/(OPJ_PATH_LEN * sizeof(char))){
free(dirptr);
return EXIT_FAILURE;
}else{
dirptr->filename_buf = (char*) calloc((size_t) num_images,
OPJ_PATH_LEN * sizeof(char));
if (!dirptr->filename_buf) {
@ -527,13 +532,14 @@ int main(int argc, char *argv[])
goto fails;
}
for (size_t it_image = 0; it_image < num_images; it_image++) {
for (it_image = 0; it_image < num_images; it_image++) {
dirptr->filename[it_image] = dirptr->filename_buf + it_image * OPJ_PATH_LEN;
}
if (load_images(dirptr, img_fol.imgdirpath) == 1) {
goto fails;
}
}
if (num_images == 0) {
fprintf(stdout, "Folder is empty\n");
goto fails;