From 3124ce50f7537a7bd7bb3556667e20207b8ab23a Mon Sep 17 00:00:00 2001 From: Matt Robenolt Date: Thu, 7 Jan 2016 17:21:08 -0800 Subject: [PATCH] Handle invalid source encodings --- src/sentry/lang/javascript/processor.py | 14 ++++++++++++++ src/sentry/models/eventerror.py | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/sentry/lang/javascript/processor.py b/src/sentry/lang/javascript/processor.py index 7a690dd490739f..63907b20b537a8 100644 --- a/src/sentry/lang/javascript/processor.py +++ b/src/sentry/lang/javascript/processor.py @@ -344,6 +344,20 @@ def fetch_file(url, project=None, release=None, allow_scraping=True): } raise CannotFetchSource(error) + # Make sure the file we're getting back is unicode, if it's not, + # it's either some encoding that we don't understand, or it's binary + # data which we can't process. + if not isinstance(result[1], unicode): + try: + result[1] = result[1].decode('utf8') + except UnicodeDecodeError: + error = { + 'type': EventError.JS_INVALID_SOURCE_ENCODING, + 'value': 'utf8', + 'url': url, + } + raise CannotFetchSource(error) + return UrlResult(url, result[0], result[1]) diff --git a/src/sentry/models/eventerror.py b/src/sentry/models/eventerror.py index a3c62f5b662e28..b49bce2a37257e 100644 --- a/src/sentry/models/eventerror.py +++ b/src/sentry/models/eventerror.py @@ -15,6 +15,7 @@ class EventError(object): JS_MISSING_SOURCE = 'js_no_source' JS_INVALID_SOURCEMAP = 'js_invalid_source' JS_TOO_MANY_REMOTE_SOURCES = 'js_too_many_sources' + JS_INVALID_SOURCE_ENCODING = 'js_invalid_source_encoding' _messages = { INVALID_DATA: 'Discarded invalid value for parameter \'{name}\'', @@ -29,6 +30,7 @@ class EventError(object): JS_MISSING_SOURCE: 'Source code was not found for {url}', JS_INVALID_SOURCEMAP: 'Sourcemap was invalid or not parseable: {url}', JS_TOO_MANY_REMOTE_SOURCES: 'The maximum number of remote source requests was made', + JS_INVALID_SOURCE_ENCODING: 'Source file was not \'{value}\' encoding: {url}' } @classmethod