WIP: Fix #105404: The USD Input operator does not validate the file received as input. #105659

Draft
Piyush Aniruddha Udhao wants to merge 2 commits from Piyush-Aniruddha-Udhao/blender:validating-usd-input-file into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
1 changed files with 15 additions and 0 deletions

View File

@ -357,6 +357,21 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op)
char filename[FILE_MAX];
RNA_string_get(op->ptr, "filepath", filename);
/* Index to find the length of the file name. */
int i = 0;
while (filename[i] != '\0') {
i++;
}
/* If the file name does not end with '.usd', it is invalid. */
if (!(filename[i - 4] == '.' &&
filename[i - 3] == 'u' &&
filename[i - 2] == 's' &&
filename[i - 1] == 'd')) {
BKE_report(op->reports, RPT_ERROR_INVALID_INPUT, "Invalid Filename");
return OPERATOR_CANCELLED;
}
eUSDOperatorOptions *options = (eUSDOperatorOptions *)op->customdata;
const bool as_background_job = (options != NULL && options->as_background_job);
MEM_SAFE_FREE(op->customdata);