Skip to content
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

Bugfix: SIPI crashed for some invalid IIIF url's #335

Merged
merged 1 commit into from
Nov 6, 2020
Merged
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
32 changes: 16 additions & 16 deletions src/SipiHttpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,10 +1051,10 @@ namespace Sipi {
if (qualform_ok || rotation_ok || size_ok || region_ok) {
std::stringstream errmsg;
errmsg << "IIIF url not correctly formatted:";
if (!qualform_ok) errmsg << " Error in quality: \"" << parts[parts.size() - 1] << "\"!";
if (!rotation_ok) errmsg << " Error in rotation: \"" << parts[parts.size() - 2] << "\"!";
if (!size_ok) errmsg << " Error in size: \"" << parts[parts.size() - 3] << "\"!";
if (!region_ok) errmsg << " Error in region: \"" << parts[parts.size() - 4] << "\"!";
if (!qualform_ok && (parts.size() > 0)) errmsg << " Error in quality: \"" << parts[parts.size() - 1] << "\"!";
if (!rotation_ok && (parts.size() > 1)) errmsg << " Error in rotation: \"" << parts[parts.size() - 2] << "\"!";
if (!size_ok && (parts.size() > 2)) errmsg << " Error in size: \"" << parts[parts.size() - 3] << "\"!";
if (!region_ok && (parts.size() > 3)) errmsg << " Error in region: \"" << parts[parts.size() - 4] << "\"!";
send_error(conn_obj, Connection::BAD_REQUEST, errmsg.str());
return;
}
Expand All @@ -1070,10 +1070,10 @@ namespace Sipi {
} else {
std::stringstream errmsg;
errmsg << "IIIF url not correctly formatted:";
if (!qualform_ok) errmsg << " Error in quality: \"" << parts[parts.size() - 1] << "\"!";
if (!rotation_ok) errmsg << " Error in rotation: \"" << parts[parts.size() - 2] << "\"!";
if (!size_ok) errmsg << " Error in size: \"" << parts[parts.size() - 3] << "\"!";
if (!region_ok) errmsg << " Error in region: \"" << parts[parts.size() - 4] << "\"!";
if (!qualform_ok && (parts.size() > 0)) errmsg << " Error in quality: \"" << parts[parts.size() - 1] << "\"!";
if (!rotation_ok && (parts.size() > 1)) errmsg << " Error in rotation: \"" << parts[parts.size() - 2] << "\"!";
if (!size_ok && (parts.size() > 2)) errmsg << " Error in size: \"" << parts[parts.size() - 3] << "\"!";
if (!region_ok && (parts.size() > 3)) errmsg << " Error in region: \"" << parts[parts.size() - 4] << "\"!";
send_error(conn_obj, Connection::BAD_REQUEST, errmsg.str());
return;
}
Expand Down Expand Up @@ -1109,10 +1109,10 @@ namespace Sipi {
if (qualform_ok || rotation_ok || size_ok || region_ok) {
std::stringstream errmsg;
errmsg << "IIIF url not correctly formatted:";
if (!qualform_ok) errmsg << " Error in quality: \"" << parts[parts.size() - 1] << "\"!";
if (!rotation_ok) errmsg << " Error in rotation: \"" << parts[parts.size() - 2] << "\"!";
if (!size_ok) errmsg << " Error in size: \"" << parts[parts.size() - 3] << "\"!";
if (!region_ok) errmsg << " Error in region: \"" << parts[parts.size() - 4] << "\"!";
if (!qualform_ok && (parts.size() > 0)) errmsg << " Error in quality: \"" << parts[parts.size() - 1] << "\"!";
if (!rotation_ok && (parts.size() > 1)) errmsg << " Error in rotation: \"" << parts[parts.size() - 2] << "\"!";
if (!size_ok && (parts.size() > 2)) errmsg << " Error in size: \"" << parts[parts.size() - 3] << "\"!";
if (!region_ok && (parts.size() > 3)) errmsg << " Error in region: \"" << parts[parts.size() - 4] << "\"!";
send_error(conn_obj, Connection::BAD_REQUEST, errmsg.str());
return;
}
Expand All @@ -1128,10 +1128,10 @@ namespace Sipi {
} else {
std::stringstream errmsg;
errmsg << "IIIF url not correctly formatted:";
if (!qualform_ok) errmsg << " Error in quality: \"" << parts[parts.size() - 1] << "\"!";
if (!rotation_ok) errmsg << " Error in rotation: \"" << parts[parts.size() - 2] << "\"!";
if (!size_ok) errmsg << " Error in size: \"" << parts[parts.size() - 3] << "\"!";
if (!region_ok) errmsg << " Error in region: \"" << parts[parts.size() - 4] << "\"!";
if (!qualform_ok && (parts.size() > 0)) errmsg << " Error in quality: \"" << parts[parts.size() - 1] << "\"!";
if (!rotation_ok && (parts.size() > 1)) errmsg << " Error in rotation: \"" << parts[parts.size() - 2] << "\"!";
if (!size_ok && (parts.size() > 2)) errmsg << " Error in size: \"" << parts[parts.size() - 3] << "\"!";
if (!region_ok && (parts.size() > 3)) errmsg << " Error in region: \"" << parts[parts.size() - 4] << "\"!";
send_error(conn_obj, Connection::BAD_REQUEST, errmsg.str());
return;
}
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/test_02_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ def test_deny(self, manager):
"""return 401 Unauthorized if the user does not have permission to see the image"""
manager.expect_status_code("/knora/DenyLeaves.jpg/full/max/0/default.jpg", 401)

def test_iiifurl_parsing(self, manager):
"""Return 400 for invalid IIIF URL's"""
manager.expect_status_code("/unit//lena512.jp2", 400)
manager.expect_status_code("/unit/lena512.jp2/max/0/default.jpg", 400)
manager.expect_status_code("/unit/lena512.jp2/full/max/default.jpg", 400)
manager.expect_status_code("/unit/lena512.jp2/full/max/!/default.jpg", 400)
manager.expect_status_code("/unit/lena512.jp2/full/max/0/jpg", 400)


def test_read_write(self, manager):
"""read an image file, convert it to JPEG2000 and write it"""
Expand Down