Skip to content

Commit

Permalink
fix(wado-uri): crash when invalid frame number
Browse files Browse the repository at this point in the history
# Problems
- When query with invalid frame number
(i.e. input frame number bigger than DICOM's frame nubmer)
- , the raccoon will crash because of file not exist

# Solutions
- Check frame number is valid or not,
- If invalid, return 400
  • Loading branch information
Chinlinlee committed Apr 27, 2023
1 parent 5de5e19 commit b4ca0b9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions api/dicom/controller/wado.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ module.exports = async(req, res) =>
let disk = process.env.DICOM_STORE_ROOTPATH;
let oriPath = await getInstanceStorePath(param);
if (!oriPath) {
res.set('content-type' , 'application/json');
return dicomWebHandleError.sendNotFoundMessage(req , res);
}

let storeAbsPath = path.join(disk, oriPath);
if (!fs.existsSync(storeAbsPath)) {
res.set('content-type' , 'application/json');
return dicomWebHandleError.sendNotFoundMessage(req , res);
}

Expand Down Expand Up @@ -157,6 +159,12 @@ async function handleFrameNumber (param , res , dicomFile) {
let finalJpegFile = "";

let dicomJson = await getDICOMJson(param);

let isValidFrameNumber = checkIsValidFrameNumber(dicomJson, param.frameNumber);
if (!isValidFrameNumber.status) {
return dicomWebHandleError.sendBadRequestMessage(res, `invalid frame number: ${param.frameNumber}, but data's frame number is ${isValidFrameNumber.dataFrameNumber}`);
}

let transferSyntax = _.get(dicomJson ,"00020010.Value.0");
if (!dcmtkSupportTransferSyntax.includes(transferSyntax)) {
let pythonDICOM2JPEGStatus = await getJpeg[process.env.ENV]['getJpegByPydicom'](images);
Expand All @@ -179,6 +187,7 @@ async function handleFrameNumber (param , res , dicomFile) {
} else {
frame = await getFrameImage(imageRelativePath, param.frameNumber);
}

if (frame.status) {
finalJpegFile = frame.imagePath;
} else {
Expand All @@ -202,6 +211,28 @@ async function handleFrameNumber (param , res , dicomFile) {
}
}

/**
*
* @param {*} dicomJson
* @param {number} frameNumber
*/
function checkIsValidFrameNumber(dicomJson, frameNumber) {
let dataFrameNumber = _.get(dicomJson, "00280008.Value.0") | 1;
dataFrameNumber = parseInt(dataFrameNumber);

if (dataFrameNumber < frameNumber) {
return {
status: false,
dataFrameNumber
};
}

return {
status: true,
dataFrameNumber
};
}

async function getInstanceStorePath(iParam)
{
let aggregateQuery =
Expand Down

0 comments on commit b4ca0b9

Please sign in to comment.