iovisor / iovisor/bcc

print_linear_hist - IndexError: list assignment index out of range, if BPF_HISTOGRAM contains Value>1024

Open
#2,832 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
22.7k
Forks
4.1k
Avg merge
10d 4h
Merged PRs (30d)
3

Description

Well, I am doing Latency measurements based on BPF_HISTOGRAM.
In my special collection, the (linear) history collection had the contents:
Value Number_of_Occurences;
12 14407; 24 2232; 42 1245; 22 903;
13 50; 14 31; 60 78; 52 2;
18 43; 74 4; 47 11; 30 6424;
**1435 1;**
As a result, the printing routine "print_linear_hist" fails, due to the fact, that the "value" (bucket) of **1435** is **exceeding the storage "vals[]"** in "https://github.com/iovisor/bcc/blob/master/src/python/bcc/table.py", line 438 defined in the
function "def print_linear_hist(self, val_type="value", section_header="Bucket ptr","

The issue itself resides in line 441: "vals[k.value]=v.value"

else:
vals = [0] * linear_index_max
for k, v in self.items():
try:
**vals[k.value] = v.value** ###< Here the index is exceeded, the
except IndexError:
# Improve error text. If the limit proves a nusiance, this

As a quick fix, I would propose to include a check - e.g. "k.value >= linear_index_max" -
and to collect all the rest exceeding the limit is collected to the last bucket of the histogram.
E.g.
if (k.value>=linear_index_max):
vals[linear_index_max-1]+= v.value
else:
vals[k.value]=v.value

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in src/python/bcc/table.py at print_linear_hist, especially the vals[k.value] assignment and its existing IndexError handling. Reproduce the failure with a histogram bucket above linear_index_max, then verify that oversized values no longer raise an IndexError and are included in the final bucket as proposed.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, python
Domain
observability-sre
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.