Diff

plugins/mod_http_file_share.lua @ 11316:ae0461b37fbe

mod_http_file_share: Verify final file size on completion of upload
author Kim Alvefur <zash@zash.se>
date Wed, 27 Jan 2021 00:09:49 +0100
parent 11315:c52fcea39c8e
child 11317:79e1f407b6f5
line wrap: on
line diff
--- a/plugins/mod_http_file_share.lua	Tue Jan 26 14:53:43 2021 +0100
+++ b/plugins/mod_http_file_share.lua	Wed Jan 27 00:09:49 2021 +0100
@@ -173,7 +173,12 @@
 	end
 
 	if request.body_sink then
+		local final_size = request.body_sink:seek();
 		local uploaded, err = errors.coerce(request.body_sink:close());
+		if final_size ~= upload_info.filesize then
+			-- Could be too short as well, but we say the same thing
+			uploaded, err = false, 413;
+		end
 		if uploaded then
 			assert(os.rename(filename.."~", filename));
 			return 201;