syedsaqibbukhari / docanalysis

Apache License 2.0
10 stars 5 forks source link

Do not use os.system calls unless absolutely necessary #26

Open kba opened 5 years ago

kba commented 5 years ago
ag os.system

ocrd_anybaseocr/cli/ocrd_anybaseocr_dewarp.py
15:        os.system("python pix2pixHD/test.py --dataroot %s --checkpoints_dir ./ --name models --results_dir %s --label_nc 0 --no_instance --no_flip --resize_or_crop none --n_blocks_global 10 --n_local_enhancers 2 --gpu_ids %s --loadSize %d --fineSize %d --resize_or_crop %s" % (os.path.dirname(tmp), dest, self.param['gpu_id'], self.param['resizeHeight'], self.param['resizeWidth'], self.param['imgresize']))
58:        os.system("export CUDA_VISIBLE_DEVICES=%s" % ss)
72:        os.system("mkdir -p %s" % img_tmp_dir)
73:        os.system("cp %s %s" % (str(fname), os.path.join(img_tmp_dir, os.path.basename(str(fname)))))
76:    os.system("rm -r %s" % img_tmp_dir)

At the very least, sanitize user input! If I would provide a parameter value dataroot="foo; rm -rf ; echo --", it would expand to python pix2pixHD/test.py --dataroot foo; rm -rf / ;echo -- --checkpoints_dir [...] which is bad.