From b4ca0b9f18ef5c0f87259cbc2f7b06d48bc402cc Mon Sep 17 00:00:00 2001 From: chin Date: Thu, 27 Apr 2023 23:01:28 +0800 Subject: [PATCH] fix(wado-uri): crash when invalid frame number # 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 --- api/dicom/controller/wado.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/api/dicom/controller/wado.js b/api/dicom/controller/wado.js index 93efff1..9297c45 100644 --- a/api/dicom/controller/wado.js +++ b/api/dicom/controller/wado.js @@ -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); } @@ -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); @@ -179,6 +187,7 @@ async function handleFrameNumber (param , res , dicomFile) { } else { frame = await getFrameImage(imageRelativePath, param.frameNumber); } + if (frame.status) { finalJpegFile = frame.imagePath; } else { @@ -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 =