diff --git a/src/managesieve/cmd-putscript.c b/src/managesieve/cmd-putscript.c
index a7c3230d62d969c9a6803208e5c84f8743b9fadc..0c782d88feba1dab223974e2686545a76ccc918d 100644
--- a/src/managesieve/cmd-putscript.c
+++ b/src/managesieve/cmd-putscript.c
@@ -183,6 +183,11 @@ static bool cmd_putscript_finish_parsing(struct client_command_context *cmd)
 
 		/* If quoted string, the size was not known until now */
 		if ( ctx->script_size == 0 ) {
+			if (sieve_script_get_size(script, &ctx->script_size) < 0) {
+				client_send_storage_error(client, ctx->storage);
+				cmd_putscript_finish(ctx);
+				return TRUE;
+			}
 			/* Check quota; max size is already checked */
 			if ( ctx->scriptname != NULL && !managesieve_quota_check_all
 					(client, ctx->scriptname, ctx->script_size) ) {