Skip to content

Fix security vulnerabilities #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,24 @@ def get_detections():
images = request.files.getlist("images")
image_names = []
for image in images:
image_name = image.filename
image_name = "./temp/" + image.filename
image_names.append(image_name)
image.save(os.path.join(os.getcwd(), image_name))
img_raw = tf.image.decode_image(
open(image_name, 'rb').read(), channels=3)
image.save(os.path.join(os.getcwd(), image_name[2:]))
try:
img_raw = tf.image.decode_image(
open(image_name, 'rb').read(), channels=3)
except tf.errors.InvalidArgumentError:
# remove temporary images
for name in image_names:
os.remove(name)
abort(404, "it is not an image file or image file is an unsupported format. try jpg or png")
except Exception as e:
# remove temporary images
for name in image_names:
os.remove(name)
print(e.__class__)
print(e)
abort(500)
raw_images.append(img_raw)

num = 0
Expand Down Expand Up @@ -80,7 +93,7 @@ def get_detections():
"confidence": float("{0:.2f}".format(np.array(scores[0][i])*100))
})
response.append({
"image": image_names[j],
"image": image_names[j][7:],
"detections": responses
})
img = cv2.cvtColor(raw_img.numpy(), cv2.COLOR_RGB2BGR)
Expand All @@ -100,10 +113,21 @@ def get_detections():
@app.route('/image', methods= ['POST'])
def get_image():
image = request.files["images"]
image_name = image.filename
image.save(os.path.join(os.getcwd(), image_name))
img_raw = tf.image.decode_image(
open(image_name, 'rb').read(), channels=3)
image_name = "./temp/" + image.filename
image.save(os.path.join(os.getcwd(), image_name[2:]))
try:
img_raw = tf.image.decode_image(
open(image_name, 'rb').read(), channels=3)
except tf.errors.InvalidArgumentError:
# remove temporary image
os.remove(image_name)
abort(404, "it is not an image file or image file is an unsupported format. try jpg or png")
except Exception as e:
# remove temporary image
os.remove(image_name)
print(e.__class__)
print(e)
abort(500)
img = tf.expand_dims(img_raw, 0)
img = transform_images(img, size)

Expand Down
1 change: 1 addition & 0 deletions temp/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@