Title:
Erratic behaviour in file-download code when there is an error in a cfcontent attribute
| View in TrackerStatus/Resolution/Reason: To Fix//BugVerified
Reporter/Name(from Bugbase): A. B. / ()
Created: 01/07/2020
Components: File Management
Versions: 2018
Failure Type: Incorrectly functioning
Found In Build/Fixed In Build: 2018.0.07.316715 /
Priority/Frequency: Normal / Some users will encounter
Locale/System: / Windows 10 64 bit
Vote Count: 0
Problem Description:
Consider the usual ColdFusion file-download code involving cfheader and cfcontent. Suppose there happens to be an error in either of cfcontent's attributes "type" and "file". Then ColdFusion fails silently, sending an invalid response to the browser.
Steps to Reproduce:
We shall, without loss of generality, reproduce the bug with a PNG download. Nevertheless, the principle is the same for any arbitrary MIME type.
Run the following code 4 times, each time according to one of the specifications described below. Run the tests using the path of a PNG file on your server.
<cfscript>
/*
try {
*/
fileName="testDownloadFile.png";
mimeType="image/png";
localFilePath="C:\Users\BKBK\Desktop\images\myPic.png";
cfheader(name="Content-Disposition", value="attachment;filename=""#fileName#""");
cfcontent(type=mimeType, file=localFilePath);
/*
}
catch (any e){
writedump(var=e);
}
*/
</cfscript>
i) Run with correct values of all the variables.
ii) Run with incorrect value of MIME type, for example, "" or "imogee/png" or with incorrect value of file-path;
iii) Remove the comment tags, activating the try-catch. Again, run with incorrect value of MIME type, for example, "" or "imogee/png" or with incorrect value of file-path;
iv) If a file is generated for download in step (iii), then change its extension to HTML. Open this in a browser.
Actual Result:
i) The code works as expected, The file is duly downloaded.
ii) ColdFusion fails silently, sending an invalid response to the browser. See attached ERR_INVALID_RESPONSE.png
iii) Using try-catch seems to have an effect. A file is in fact generated for download. However the file is not a valid PNG.
iv) The HTML file contains the exception message
Expected Result:
ii) ColdFusion should send an exception/error message to the browser;
iii), iv) ColdFusion should not generate a download file containing the exception/error message;
Any Workarounds:
Not applicable
Attachments:
Comments: