anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: jacebrowning/memegen
Issue: Handle invalid width/height parameters

http://localhost:5000/images/fry/test.png?width=abc should return an image with a `4xx` status rather than crashing.

Libraries like [webargs](https://github.com/marshmallow-code/webargs) can do this, but I don't know how well that integrates with Sanic.

Changed files:
app/tests/test_apis_memes.py, app/api/memes.py

diff --git a/app/api/memes.py b/app/api/memes.py
index a8ef79a9..de4be28f 100644
--- a/app/api/memes.py
+++ b/app/api/memes.py
@@ -387,7 +387,12 @@ async def render_image(
             if style != settings.PLACEHOLDER:
                 status = 422
 
-    size = int(request.args.get("width", 0)), int(request.args.get("height", 0))
+    try:
+        size = int(request.args.get("width", 0)), int(request.args.get("height", 0))
+    except ValueError:
+        size = 0, 0
+        status = 422
+
     path = await asyncio.to_thread(
         utils.images.save, template, lines, watermark, ext=ext, style=style, size=size
     )
diff --git a/app/tests/test_apis_memes.py b/app/tests/test_apis_memes.py
index cbcefd6f..4ce6753f 100644
--- a/app/tests/test_apis_memes.py
+++ b/app/tests/test_apis_memes.py
@@ -118,6 +118,11 @@ def describe_detail():
         expect(response.status) == 404
         expect(response.headers["content-type"]) == "image/png"
 
+    def it_rejects_invalid_sizes(expect, client):
+        request, response = client.get("/images/fry/test.jpg?width=abc")
+        expect(response.status) == 422
+        expect(response.headers["content-type"]) == "image/jpeg"
+
     def it_rejects_extremely_long_urls(expect, client):
         text = "test-" * 50
         request, response = client.get(f"/images/fry/{text}.jpg")