derpibooru / philomena

Next-generation imageboard
https://derpibooru.org/
GNU Affero General Public License v3.0
219 stars 56 forks source link

[WEB] Reverse search crashing with image #68

Closed SomewhatDamaged closed 4 years ago

SomewhatDamaged commented 4 years ago

Describe the bug When reverse searching with a particular image derpibooru (I can't get my test environment to replicate) sends a 404.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://derpibooru.org/search/reverse
  2. Put https://sun9-43.userapi.com/c857436/v857436510/1ae175/A_yzs_MXmfs.jpg in the link field
  3. Click Fetch (image scrapes okay)
  4. Click Reverse Search

Expected behavior It should return that it has found image 2192334

Screenshots image

Desktop (please complete the following information):

Additional context Tried uploading it from PC, even tried saving as PNG and using that. Reverse search with API (/api/v1/json/search/reverse) works fine.

liamwhite commented 4 years ago
Server: derpibooru.org:443 (http)
Request: POST /search/reverse
** (exit) an exception was raised:
    ** (ArgumentError) unsupported scheme given to link/2. In case you want to link to an
unknown or unsafe scheme, such as javascript, use a tuple: {:javascript, rest}

        (phoenix_html 2.14.0) lib/phoenix_html/link.ex:260: Phoenix.HTML.Link.valid_string_destination!/2
        (phoenix_html 2.14.0) lib/phoenix_html/link.ex:144: Phoenix.HTML.Link.link/2
        (philomena 0.1.0) lib/philomena_web/templates/search/reverse/index.html.slime:1: anonymous fn/3 in PhilomenaWeb.Search.ReverseView."index.html"/1
        (elixir 1.10.2) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
        (philomena 0.1.0) lib/philomena_web/templates/search/reverse/index.html.slime:1: PhilomenaWeb.Search.ReverseView."index.html"/1
        (philomena 0.1.0) lib/philomena_web/templates/layout/app.html.slime:1: PhilomenaWeb.LayoutView."app.html"/1
        (phoenix 1.4.12) lib/phoenix/view.ex:410: Phoenix.View.render_to_iodata/3
        (phoenix 1.4.12) lib/phoenix/controller.ex:729: Phoenix.Controller.__put_render__/5

It's an error in the source url of an image result. It has a space before it and link/2 doesn't like that.

SomewhatDamaged commented 4 years ago

I tested adding a space into another source, and that didn't cause a problem.

The image in particular has a source of artist:zlatavector. Perhaps we should be doing URL validation when people enter the data if we expect a valid URL to be there?

liamwhite commented 4 years ago

The source field is stripped on entry. I was too quick to judge the problem as an extra space, as any provided input that is not a HTTP(S) URL will raise an error inside link/2 (it just so happens that extra spaces are the most common way this happens).

liamwhite commented 4 years ago

There are 8312 known examples of source URLs which will fail to work with link/2. I have made a list of them for staff to help fix.

liamwhite commented 4 years ago

Okay, we've gone through and fixed all of these. Shouldn't happen anymore.