Skip to content

Integer overflow in TTree::Draw #20228

@vepadulano

Description

@vepadulano

Check duplicate issues.

  • Checked for duplicates

Description

Equivalent of #20226, but for TTree::Draw. In this case it's slightly more difficult to trigger the integer overflow, albeit absolutely doable. a run of the reproducer shows an empty histogram, thus confirming that the overflow prevents the loop from even starting. This is due to (in the case nentries==TTree::kMaxEntries)

for (entry=firstentry;entry<firstentry+nentries;entry++) {

Guarded by this innocent-looking line

// Do not process more than fMaxEntryLoop entries
if (nentries > fTree->GetMaxEntryLoop()) nentries = fTree->GetMaxEntryLoop();

Reproducer

#include <TChain.h>
#include <TFile.h>
#include <TTree.h>

#include <memory>
#include <iostream>

void make_step_one_file(const char *name, const char *treename, int nEntries)
{
    auto file = std::make_unique<TFile>(name, "RECREATE");
    auto tree = std::make_unique<TTree>(treename, treename);

    for (int i = 0; i < nEntries; ++i)
    {
        tree->Fill();
    }

    file->Write();
}

void make_step_zero_file(const char *name, const char *treename, int first, int last)
{
    auto file = std::make_unique<TFile>(name, "RECREATE");
    auto tree = std::make_unique<TTree>(treename, treename);

    int index{};
    int value{};
    tree->Branch("index", &index);
    tree->Branch("value", &value);

    for (index = first; index < last; ++index)
    {
        value = 2 * index;
        tree->Fill();
    }

    file->Write();
}

void ttree_scan_int_overflow()
{
    make_step_zero_file("friends-hybrid-step0-0.root", "stepzerotree", 0, 10);
    auto file = std::make_unique<TFile>("friends-hybrid-step0-0.root");
    std::unique_ptr<TTree> tree{file->Get<TTree>("stepzerotree")};

    tree->SetMaxEntryLoop(TTree::kMaxEntries);

    std::cout << tree->Draw("index", "", "", TTree::kMaxEntries, 3) << "\n";
}

int main()
{
    ttree_scan_int_overflow();
}

ROOT version

Any

Installation method

Any

Operating system

Any

Additional context

No response

Metadata

Metadata

Labels

bugexperimentAffects an experiment / reported by its software & computimng expertsin:TTree

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions