Skip to content
Merged
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
17 changes: 12 additions & 5 deletions src/appengine/handlers/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,20 @@ def get(self):
if not access.has_access():
raise helpers.AccessDeniedException()

if blobs.get_blob_size(key) > MAX_ALLOWED_CONTENT_SIZE:
blob_size = blobs.get_blob_size(key)
if blob_size > MAX_ALLOWED_CONTENT_SIZE:
raise helpers.EarlyExitException('Content exceeds max allowed size.', 400)

try:
content = unicode(blobs.read_key(key), errors='replace')
except Exception:
raise helpers.EarlyExitException('Failed to read content.', 400)
# TODO(mbarbella): Workaround for an issue in the Cloud Storage API. Remove
# once it is fixed properly upstream:
# https://github.com/googleapis/google-cloud-python/issues/6572
if blob_size:
try:
content = unicode(blobs.read_key(key), errors='replace')
Copy link
Collaborator

@inferno-chromium inferno-chromium Jul 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe remove this unicode replacement hack along the way and fix https://bugs.chromium.org/p/chromium/issues/detail?id=920160 :) stage to make sure it works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to cause issues later in template rendering, which I guess explains why we had the hack initially. I'm going to leave it out of this change.

except Exception:
raise helpers.EarlyExitException('Failed to read content.', 400)
else:
content = u''

line_count = len(content.splitlines())
size = len(content)
Expand Down