Bug 1438561 - Restrict histogram bucket ranges to INT_MAX. r=chutten

This commit is contained in:
Issei Horie 2018-04-29 14:29:10 +09:00
Родитель 60a2631090
Коммит 659145e037
2 изменённых файлов: 29 добавлений и 0 удалений

Просмотреть файл

@ -12,6 +12,7 @@ import sys
import atexit
import shared_telemetry_utils as utils
from ctypes import c_int
from shared_telemetry_utils import ParserError
from collections import OrderedDict
atexit.register(ParserError.exit_func)
@ -487,6 +488,11 @@ associated with the histogram. Returns None if no guarding is necessary."""
ParserError('Value for key "{0}" in histogram "{1}" should be {2}.'
.format(key, name, nice_type_name(key_type))).handle_later()
# Make sure the max range is lower than or equal to INT_MAX
if "high" in definition and not c_int(definition["high"]).value > 0:
ParserError('Value for high in histogram "{0}" should be lower or equal to INT_MAX.'
.format(nice_type_name(c_int))).handle_later()
for key, key_type in type_checked_list_fields.iteritems():
if key not in definition:
continue

Просмотреть файл

@ -122,6 +122,29 @@ class TestParser(unittest.TestCase):
parse_histograms.whitelists = None
def test_high_value(self):
SAMPLE_HISTOGRAM = {
"TEST_HISTOGRAM_WHITELIST_N_BUCKETS": {
"record_in_processes": ["main", "content"],
"alert_emails": ["team@mozilla.xyz"],
"bug_numbers": [1383793],
"expires_in_version": "never",
"kind": "exponential",
"low": 1024,
"high": 2 ** 64,
"n_buckets": 100,
"description": "Test histogram",
}
}
histograms = load_histogram(SAMPLE_HISTOGRAM)
parse_histograms.load_whitelist()
parse_histograms.Histogram('TEST_HISTOGRAM_WHITELIST_N_BUCKETS',
histograms['TEST_HISTOGRAM_WHITELIST_N_BUCKETS'],
strict_type_checks=True)
self.assertRaises(SystemExit, ParserError.exit_func)
def test_high_n_buckets(self):
SAMPLE_HISTOGRAM = {
"TEST_HISTOGRAM_WHITELIST_N_BUCKETS": {