Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] lavfi/dnn: Fix OpenVINO missing model file corrupt issue.
@ 2022-08-04  9:31 Ting Fu
  2022-08-04 10:39 ` Anton Khirnov
  0 siblings, 1 reply; 4+ messages in thread
From: Ting Fu @ 2022-08-04  9:31 UTC (permalink / raw)
  To: ffmpeg-devel

DNN OpenVINO backend would not report missing model file if it does not
exist. It would corrupt directly with out any error infomation. This commit
would check both .xml and .bin file existance before loading model.

Signed-off-by: Ting Fu <ting.fu@intel.com>
---
 libavfilter/dnn/dnn_backend_openvino.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c
index b494f26f55..47e3fc8280 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -34,6 +34,7 @@
 #include "../internal.h"
 #include "safe_queue.h"
 #include <c_api/ie_c_api.h>
+#include <unistd.h>
 #include "dnn_backend_common.h"
 
 typedef struct OVOptions{
@@ -728,7 +729,7 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, DNNFunctionType func_
     OVContext *ctx = NULL;
     IEStatusCode status;
     size_t node_count = 0;
-    char *node_name = NULL;
+    char *node_name, *model_binary_file, *extension_chr = NULL;
 
     model = av_mallocz(sizeof(DNNModel));
     if (!model){
@@ -758,6 +759,22 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, DNNFunctionType func_
     if (status != OK)
         goto err;
 
+    //file existance check
+    model_binary_file = (char *)malloc(sizeof(model_filename));
+    strcpy(model_binary_file, model_filename);
+    extension_chr = strstr(model_binary_file, ".xml");
+    if (!extension_chr) {
+        av_log(ctx, AV_LOG_ERROR, "Model file name \"%s\" with incorrect extension.",
+               model_filename);
+        goto err;
+    }
+    strcpy(extension_chr, ".bin");
+    if (access(model_filename, F_OK) || access(model_binary_file, F_OK)) {
+        av_log(ctx, AV_LOG_ERROR, "Model file \"%s\" or \"%s\" does not exist.",
+               model_filename, model_binary_file);
+        goto err;
+    }
+
     status = ie_core_read_network(ov_model->core, model_filename, NULL, &ov_model->network);
     if (status != OK) {
         ie_version_t ver;
@@ -806,6 +823,7 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, DNNFunctionType func_
     return model;
 
 err:
+    free(model_binary_file);
     ff_dnn_free_model_ov(&model);
     return NULL;
 }
-- 
2.17.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [FFmpeg-devel] [PATCH] lavfi/dnn: Fix OpenVINO missing model file corrupt issue.
  2022-08-04  9:31 [FFmpeg-devel] [PATCH] lavfi/dnn: Fix OpenVINO missing model file corrupt issue Ting Fu
@ 2022-08-04 10:39 ` Anton Khirnov
  2022-08-05  3:34   ` Fu, Ting
  2022-08-06 12:57   ` Anton Khirnov
  0 siblings, 2 replies; 4+ messages in thread
From: Anton Khirnov @ 2022-08-04 10:39 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting Ting Fu (2022-08-04 11:31:01)
> DNN OpenVINO backend would not report missing model file if it does not
> exist. It would corrupt directly with out any error infomation. This commit

"corrupt"?

The patch looks completely wrong. Testing for file existence explicitly
is known to be a bad pattern that leads to all kinds of races, security
issues, and other bugs. Just trying to open the file and returning an
error if that fails is the right thing to do.

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [FFmpeg-devel] [PATCH] lavfi/dnn: Fix OpenVINO missing model file corrupt issue.
  2022-08-04 10:39 ` Anton Khirnov
@ 2022-08-05  3:34   ` Fu, Ting
  2022-08-06 12:57   ` Anton Khirnov
  1 sibling, 0 replies; 4+ messages in thread
From: Fu, Ting @ 2022-08-05  3:34 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Hi Anton,

Thank you for comment. 
After double checked the OpenVINO, it is true that the code would corrupt if the binary file does not exist.
We would have nothing to do in this case, that's why I code to check the file existence explicitly.
Yes, you are right, it is not a proper way to do like this. But I have no idea how to solve it more decently, since trying to open it as you mentioned would lead to crush immediately. Maybe there is some solution I don’t know, any further input would be appreciated. 😊

PS, it is not a good commit message since I have not fixed this issue, it's just a workaround. I would modify it in next version.

Thank you,
Ting FU
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Anton
> Khirnov
> Sent: Thursday, August 4, 2022 06:40 PM
> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] lavfi/dnn: Fix OpenVINO missing model file
> corrupt issue.
> 
> Quoting Ting Fu (2022-08-04 11:31:01)
> > DNN OpenVINO backend would not report missing model file if it does
> > not exist. It would corrupt directly with out any error infomation.
> > This commit
> 
> "corrupt"?
> 
> The patch looks completely wrong. Testing for file existence explicitly is known
> to be a bad pattern that leads to all kinds of races, security issues, and other
> bugs. Just trying to open the file and returning an error if that fails is the right
> thing to do.
> 
> --
> Anton Khirnov
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org
> with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [FFmpeg-devel] [PATCH] lavfi/dnn: Fix OpenVINO missing model file corrupt issue.
  2022-08-04 10:39 ` Anton Khirnov
  2022-08-05  3:34   ` Fu, Ting
@ 2022-08-06 12:57   ` Anton Khirnov
  1 sibling, 0 replies; 4+ messages in thread
From: Anton Khirnov @ 2022-08-06 12:57 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting Fu, Ting (2022-08-05 05:34:30)
> Hi Anton,
> 
> Thank you for comment. 
> After double checked the OpenVINO, it is true that the code would corrupt if the binary file does not exist.

Can you be more specific about what do you mean by "corrupt"?

> We would have nothing to do in this case, that's why I code to check the file existence explicitly.
> Yes, you are right, it is not a proper way to do like this. But I have no idea how to solve it more decently, since trying to open it as you mentioned would lead to crush immediately. Maybe there is some solution I don’t know, any further input would be appreciated. 😊

It should be fixed in OpenVINO, and we should disallow any older
versions from being used in lavfi. Your patch is still susceptible to
someone removing the file after the access() call.

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-08-06 12:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-04  9:31 [FFmpeg-devel] [PATCH] lavfi/dnn: Fix OpenVINO missing model file corrupt issue Ting Fu
2022-08-04 10:39 ` Anton Khirnov
2022-08-05  3:34   ` Fu, Ting
2022-08-06 12:57   ` Anton Khirnov

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git