[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/3] use CPU rlimit to limit soxi||ffprobe run time
From: |
Eric Wong |
Subject: |
[PATCH 2/3] use CPU rlimit to limit soxi||ffprobe run time |
Date: |
Fri, 26 Apr 2024 07:04:14 +0000 |
soxi or ffprobe may infinite loop on bad files, so be sure to
let these processes timeout properly.
---
bin/dtas-readahead | 2 +-
lib/dtas/source/av_ff_common.rb | 2 +-
lib/dtas/source/sox.rb | 3 ++-
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/bin/dtas-readahead b/bin/dtas-readahead
index f2ab514..c61d317 100755
--- a/bin/dtas-readahead
+++ b/bin/dtas-readahead
@@ -25,7 +25,7 @@
c = DTAS::UNIXClient.new
@max_ra = 30 * 1024 * 1024
null = DTAS.null
-@redir = { err: null, out: null, in: null }.freeze
+@redir = { err: null, out: null, in: null, rlimit_cpu: [ 1, 2 ] }.freeze
require 'pp'
def seek_to_cur_pos(cur_pid, fp)
diff --git a/lib/dtas/source/av_ff_common.rb b/lib/dtas/source/av_ff_common.rb
index c600c48..7f197e0 100644
--- a/lib/dtas/source/av_ff_common.rb
+++ b/lib/dtas/source/av_ff_common.rb
@@ -92,7 +92,7 @@ def av_ff_ok?
err = "".b
begin
- s = qx(@env, cmd, err_str: err, no_raise: true)
+ s = qx(@env, cmd, err_str: err, no_raise: true, rlimit_cpu: [ 1, 2 ])
rescue Errno::ENOENT # avprobe/ffprobe not installed
return false
end
diff --git a/lib/dtas/source/sox.rb b/lib/dtas/source/sox.rb
index c03477e..365c7b6 100644
--- a/lib/dtas/source/sox.rb
+++ b/lib/dtas/source/sox.rb
@@ -39,7 +39,8 @@ def initialize(mcache = nil)
def mcache_lookup(infile)
(@mcache ||= DTAS::Mcache.new).lookup(infile) do |input, dst|
err = ''.b
- out = qx(@env.dup, %W(soxi #{input}), err_str: err, no_raise: true)
+ out = qx(@env.dup, %W(soxi #{input}), err_str: err, no_raise: true,
+ rlimit_cpu: [ 1, 2 ])
return soxi_failed(infile, out) if Process::Status === out
return soxi_failed(infile, err) if err =~ /soxi FAIL formats:/
out =~ /^Duration\s*:[^=]*= (\d+) samples /n