def get(self): """Get the HTML page.""" key = self.request.get('key') if not key: raise helpers.EarlyExitException('No key provided.', 400) testcase_id = self.request.get('testcase_id') if testcase_id: testcase = helpers.get_testcase(testcase_id) if not access.can_user_access_testcase(testcase): raise helpers.AccessDeniedException() if key not in [testcase.fuzzed_keys, testcase.minimized_keys]: raise helpers.AccessDeniedException() else: if not access.has_access(): raise helpers.AccessDeniedException() if blobs.get_blob_size(key) > 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) line_count = len(content.splitlines()) size = len(content) title = '%s, %s' % (utils.get_line_count_string(line_count), utils.get_size_string(size)) self.render('viewer.html', {'content': content, 'title': title})
def _get_blob_size_string(blob_key): """Return blob size string.""" blob_size = blobs.get_blob_size(blob_key) if blob_size is None: return None return utils.get_size_string(blob_size)
def get(self, group_by, group_by_value): """Return data.""" if (self.ctx.fuzzer in data_types.BUILTIN_FUZZERS and group_by == QueryGroupBy.GROUP_BY_DAY): # Explicitly return None here, as coverage_info below might exist and have # default corpus size of 0, which might look confusing on the stats page. return None coverage_info = self.get_coverage_info(group_by, group_by_value) if not coverage_info: return None if self.corpus_type == self.CORPUS: corpus_size_units = coverage_info.corpus_size_units corpus_size_bytes = coverage_info.corpus_size_bytes corpus_location = coverage_info.corpus_location else: corpus_size_units = coverage_info.quarantine_size_units corpus_size_bytes = coverage_info.quarantine_size_bytes corpus_location = coverage_info.quarantine_location # If the values aren't specified, return None to show the default '--' text. if corpus_size_units is None or corpus_size_bytes is None: return None display_value = '%d (%s)' % (corpus_size_units, utils.get_size_string(corpus_size_bytes)) return BuiltinFieldData(display_value, sort_key=corpus_size_units, link=corpus_location)
def _get_blob_size_string(blob_key): """Return blob size string.""" if not blob_key or blob_key == 'NA': return '' try: blob_size = blobs.get_blob_size(blob_key) if blob_size is None: return '' except: return '' return utils.get_size_string(blob_size)
def get(self): """Get the HTML page.""" key = request.get('key') if not key: raise helpers.EarlyExitException('No key provided.', 400) testcase_id = request.get('testcase_id') if testcase_id: testcase = helpers.get_testcase(testcase_id) if not access.can_user_access_testcase(testcase): raise helpers.AccessDeniedException() if key not in [testcase.fuzzed_keys, testcase.minimized_keys]: raise helpers.AccessDeniedException() else: if not access.has_access(): raise helpers.AccessDeniedException() blob_size = blobs.get_blob_size(key) if blob_size > MAX_ALLOWED_CONTENT_SIZE: raise helpers.EarlyExitException( 'Content exceeds max allowed size.', 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 = blobs.read_key(key).decode('utf-8', errors='replace') except Exception: raise helpers.EarlyExitException('Failed to read content.', 400) else: content = u'' line_count = len(content.splitlines()) size = len(content) title = '%s, %s' % (utils.get_line_count_string(line_count), utils.get_size_string(size)) return self.render('viewer.html', {'content': content, 'title': title})
def test_size_gigabytes(self): """Test size returned in gigabytes.""" self.assertEqual(utils.get_size_string(1073741824), '1 GB') self.assertEqual(utils.get_size_string(5000000000), '4 GB')
def test_size_megabytes(self): """Test size returned in megabytes.""" self.assertEqual(utils.get_size_string(1048576), '1 MB') self.assertEqual(utils.get_size_string(1073741823), '1023 MB')
def test_size_kilobytes(self): """Test size returned in kilobytes.""" self.assertEqual(utils.get_size_string(1024), '1 KB') self.assertEqual(utils.get_size_string(1048575), '1023 KB')
def test_size_bytes(self): """Test size returned in bytes.""" self.assertEqual(utils.get_size_string(10), '10 B') self.assertEqual(utils.get_size_string(1023), '1023 B')
def apply_fuzzer_changes(self, fuzzer, upload_info): """Apply changes to a fuzzer.""" if upload_info and not archive.is_archive(upload_info.filename): raise helpers.EarlyExitException( 'Sorry, only zip, tgz, tar.gz, tbz, and tar.bz2 archives are ' 'allowed!', 400) if fuzzer.builtin: executable_path = launcher_script = None else: executable_path = self._get_executable_path(upload_info) launcher_script = self._get_launcher_script(upload_info) # Executable path is required for non-builtin fuzzers and if it is not # already set. if not fuzzer.executable_path and not executable_path: raise helpers.EarlyExitException( 'Please enter the path to the executable, or if the archive you ' 'uploaded is less than 16MB, ensure that the executable file has ' '"run" in its name.', 400) jobs = self.request.get('jobs', []) timeout = self._get_integer_value('timeout') max_testcases = self._get_integer_value('max_testcases') external_contribution = self.request.get('external_contribution', False) differential = self.request.get('differential', False) environment_string = self.request.get('additional_environment_string') data_bundle_name = self.request.get('data_bundle_name') # Save the fuzzer file metadata. if upload_info: fuzzer.filename = upload_info.filename fuzzer.blobstore_key = str(upload_info.key()) fuzzer.file_size = utils.get_size_string(upload_info.size) fuzzer.jobs = jobs fuzzer.revision = fuzzer.revision + 1 fuzzer.source = helpers.get_user_email() fuzzer.timeout = timeout fuzzer.max_testcases = max_testcases fuzzer.result = None fuzzer.sample_testcase = None fuzzer.console_output = None fuzzer.external_contribution = bool(external_contribution) fuzzer.differential = bool(differential) fuzzer.additional_environment_string = environment_string fuzzer.timestamp = datetime.datetime.utcnow() fuzzer.data_bundle_name = data_bundle_name # Update only if a new archive is provided. if executable_path: fuzzer.executable_path = executable_path # Optional. Also, update only if a new archive is provided and contains a # launcher script. if launcher_script: fuzzer.launcher_script = launcher_script fuzzer.put() fuzzer_selection.update_mappings_for_fuzzer(fuzzer) helpers.log('Uploaded fuzzer %s.' % fuzzer.name, helpers.MODIFY_OPERATION) self.redirect('/fuzzers')