DEV Community

Cover image for When 010 means 8: parsing a GitLab env var as base 10
Priyanshu Jha
Priyanshu Jha

Posted on

When 010 means 8: parsing a GitLab env var as base 10

Ruby will happily turn 010 into 8. That's not a typo. Integer without a base treats a leading zero as octal, and a concurrency limit of ten becomes a limit of eight.

This is the story of gitlab-org/gitlab!270247, a small parse fix in Duo Workflow's business-logic security scan limit. I'll cover the gotcha, the one extra argument that removes it, and the spec that fails if someone takes the base back out.

The issue: a limit you could not type in decimal

The issue was gitlab-org/gitlab#639683, opened by Meir Benayoun after Mohamed Hamda raised it in review of !268212, which had just added the limit.

Ops can raise or lower how many of those scans may run at once in a root namespace with DUO_WORKFLOW_MAX_CONCURRENT_BL_SECURITY_SCANS_PER_GROUP. The default is 20. A value of 0 or less turns the cap off. The parser looked like this:

Integer(ENV.fetch('DUO_WORKFLOW_MAX_CONCURRENT_BL_SECURITY_SCANS_PER_GROUP', default), exception: false) ||
  default
Enter fullscreen mode Exit fullscreen mode

Integer with no base follows Ruby's rules for a signed integer literal. A leading 0 is octal. A leading 0x is hexadecimal. So:

Value Before After
010 8 10
09 default (invalid octal) 9
0x10 16 default
unset / many default default

09 is the one that surprises people twice. It is not a valid octal digit string, so Integer with exception: false returned nil and the code fell back to the default. Nobody setting a limit of nine would expect that.

The issue already had the shape of the fix: pass an explicit base of 10, and give ENV.fetch a string default, because Integer with a base does not accept an Integer as its first argument.

The fix: base 10, and a string default

The production change is in Ai::DuoWorkflows::CreateWorkflowService#max_active_bl_security_scans:

def max_active_bl_security_scans
  default = DEFAULT_MAX_ACTIVE_BL_SECURITY_SCANS_PER_ROOT_NAMESPACE
  value = ENV.fetch('DUO_WORKFLOW_MAX_CONCURRENT_BL_SECURITY_SCANS_PER_GROUP', default.to_s)

  # Base 10 so a leading zero is not read as octal (`010` is 10, not 8).
  Integer(value, 10, exception: false) || default
end
Enter fullscreen mode Exit fullscreen mode

Two details are easy to skip.

The base has to be in the Integer call, not in a comment. Integer("010") is 8. Integer("010", 10) is 10. exception: false still turns a junk value into nil, so many or 0x10 still falls back to the default. Hexadecimal is no longer accepted, which is what you want from a decimal env var.

The default has to be a string at fetch time. The old code passed default (an Integer, 20 in production) straight into ENV.fetch. That is fine when Integer is called with one argument. It is not fine once you add a base: Integer(20, 10) raises, because the first argument must be a string. default.to_s keeps the "unset" path valid.

Values of 0 or less still disable the limit. That behaviour did not change.

A spec that fails on octal, not just on the happy path

The scan-limit examples already stubbed the default down to 2 and set up two active scans, so the next create is refused. The new example stays inside that setup, stubs the env var to '010', and starts six more running scans:

context 'when the limit variable has a leading zero' do
  before do
    stub_env('DUO_WORKFLOW_MAX_CONCURRENT_BL_SECURITY_SCANS_PER_GROUP', '010')
    create_list(:duo_workflows_workflow, 6, :running, workflow_definition: bl_security, project: project,
      user: user)
  end

  it 'reads it as a decimal limit, not octal' do
    expect { execute }.to change { Ai::DuoWorkflows::Workflow.count }.by(1)
  end
end
Enter fullscreen mode Exit fullscreen mode

There are eight active scans when execute runs. If the parser still used octal, the limit would be 8 and the create would be refused. With base 10 the limit is 10, and the scan is created. The example is not "'010' becomes 10 in isolation." It is "a group that is already at the octal cap is still allowed to go to ten."

I also did not add a changelog entry. Meir pointed out why, when he approved the MR: the limit landed in !268212 for the same release, so this is a correction of a feature that has not shipped on its own.

The review

Meir reviewed it the same day and approved it:

The spec bites: with 8 active scans, octal parsing would refuse the scan, and base 10 lets it through. The before/after table in the description makes the change easy to review.

That is the bar I want for a parser test. If you can delete the , 10 and the example still passes, it is not testing the bug.

The MR merged on 12 November 2026.

What I took away

1. Integer(value) is not "parse a decimal." It is "parse a Ruby integer literal." Leading zeros, 0x, and 0b are all in play unless you pass a base.

2. exception: false is not a substitute for a base. It only decides what happens when the string is invalid. 010 is valid octal. The call succeeds, and you get the wrong number.

3. Adding a base can break a default that used to work. Integer(20, 10) is not a valid call. If the fallback comes from ENV.fetch's default, that default has to be a string.

4. Put the example on the side of the limit that the bug would refuse. Eight active scans and a value of 010 is a tighter test than expect(Integer("010", 10)).to eq(10), because it runs through the service and the soft cap.

Links

Thanks to Mohamed Hamda for catching the parse in review, and to Meir Benayoun for the issue, the proposed shape of the fix, and a review that checked the spec actually bites.

If you've been thinking about contributing to GitLab, the community issues are a great place to start: contributors.gitlab.com.

Top comments (1)

Collapse
 
userxnom profile image
Abdullah Naseer •

The '09' row is the one that would have bitten me hardest — '010' at least gives you a number, just the wrong one, but '09' silently falls back to the default 20, so an ops person asking for 9 concurrent scans actually gets more than double that with no error anywhere.

Your test-design bar is the part I'm stealing: if you can delete the ', 10' and the example still passes, it's not testing the bug. The 8-active-scans setup tests the boundary on exactly the side the bug would refuse, which is a much stronger check than asserting Integer("010", 10) equals 10 in isolation.

Did you grep for other Integer(ENV... calls in the codebase while you were in there — is this the only place the pattern lived, or are there siblings waiting to bite the same way?