Skip to content

fix out-of-bound read processing time zone data with distant-past dates#15

Merged
Ana Pazos (apazos) merged 1 commit into
qualcomm:mainfrom
UsmanNadeem:OOB_Fix
Feb 25, 2026
Merged

fix out-of-bound read processing time zone data with distant-past dates#15
Ana Pazos (apazos) merged 1 commit into
qualcomm:mainfrom
UsmanNadeem:OOB_Fix

Conversation

@UsmanNadeem

@UsmanNadeem Usman Nadeem (UsmanNadeem) commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

this bug goes back to commit 1cc81f5 where zoneinfo file support was first added. in scan_trans, which searches for the appropriate local time/dst rule in effect at a given time, times prior to the second transition time caused the -1 slot of the index to be read to determine the previous rule in effect. this memory was always valid (part of another zoneinfo table in the mapped file) but the byte value read was then used to index another table, possibly going outside the bounds of the mmap. most of the time, the result was limited to misinterpretation of the rule in effect at that time (pre-1900s), but it could produce a crash if adjacent memory was not readable.

the root cause of the problem, however, was that the logic for this code path was all wrong. as documented in the comment, times before the first transition should be treated as using the lowest-numbered non-dst rule, or rule 0 if no non-dst rules exist. if the argument is in units of local time, however, the rule prior to the first transition is needed to determine if it falls before or after it, and that's where the -1 index was wrongly used.

instead, use the documented logic to find out what rule would be in effect before the first transition, and apply it as the offset if the argument was given in local time.

the new code has not been heavily tested, but no longer performs potentially out-of-bounds accesses, and successfully handles the 1883 transition from local mean time to central standard time in the test case the error was reported for.

(cherry picked from commit 3b7b4155570b4b9054465785be2992c92cb7d7b1)
Signed-off-by: Usman Nadeem mnadeem@qti.qualcomm.com

this bug goes back to commit 1cc81f5
where zoneinfo file support was first added. in scan_trans, which
searches for the appropriate local time/dst rule in effect at a given
time, times prior to the second transition time caused the -1 slot of
the index to be read to determine the previous rule in effect. this
memory was always valid (part of another zoneinfo table in the mapped
file) but the byte value read was then used to index another table,
possibly going outside the bounds of the mmap. most of the time, the
result was limited to misinterpretation of the rule in effect at that
time (pre-1900s), but it could produce a crash if adjacent memory was
not readable.

the root cause of the problem, however, was that the logic for this
code path was all wrong. as documented in the comment, times before
the first transition should be treated as using the lowest-numbered
non-dst rule, or rule 0 if no non-dst rules exist. if the argument is
in units of local time, however, the rule prior to the first
transition is needed to determine if it falls before or after it, and
that's where the -1 index was wrongly used.

instead, use the documented logic to find out what rule would be in
effect before the first transition, and apply it as the offset if the
argument was given in local time.

the new code has not been heavily tested, but no longer performs
potentially out-of-bounds accesses, and successfully handles the 1883
transition from local mean time to central standard time in the test
case the error was reported for.

(cherry picked from commit 3b7b4155570b4b9054465785be2992c92cb7d7b1)
Change-Id: I5f71f395eef71c5085d3d4e5fe07ea8ff4b3815e
Signed-off-by: Usman Nadeem <mnadeem@qti.qualcomm.com>
@apazos Ana Pazos (apazos) merged commit 09177f6 into qualcomm:main Feb 25, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants