Skip to content

Sync CodeQL fixes from Android (fastboot, ext4_utils, libfec) - #3630

Merged
adelva1984 merged 3 commits into
google:mainfrom
adelva1984:codeql-fixes
Nov 19, 2026
Merged

adelva1984 merged 3 commits into
google:mainfrom
adelva1984:codeql-fixes

Conversation

@adelva1984

Copy link
Copy Markdown
Collaborator

Cherry-picks three CodeQL integer/comparison fixes that have been upstreamed to Android:

  • fastboot (ag/43929786): Fix unsigned difference expression compared to zero in fastboot/fastboot_driver.cpp (len - total > 0 → total < len).
  • ext4_utils (ag/43928713): Avoid 32-bit overflow in lseek offset in libext4_utils/ext4_utils.cpp by casting info.block_size to off_t before multiplying by (aux_info.first_data_block + 1).
  • libfec (ag/43930329): Avoid 32-bit overflow in hashtree offset calculations in fec/libfec/fec_verity.cpp by using uint64_t for block counts and loop indices and checking hash_data_size <= PTRDIFF_MAX.

Cherry-pick from ag/43929786:

GitHub's CodeQL AI detected that this expression might "not be what the programmer intended" due to len and total both being unsigned (size_t), however in practice this code is not buggy, but to avoid the false detection change the check to a much easier to understand expression.

Change-Id: Id1b52b9a5979ada7797663447e43daad7cd04637

Assisted-by: Jetski:Gemini
Cherry-pick from ag/43928713:

Cast info.block_size to off_t before multiplying by (aux_info.first_data_block + 1) when seeking to the block group descriptors, preventing potential unsigned int overflow.

Change-Id: Ieb9c63a9875337f85855785e6f881715e0d39ea8

Assisted-by: Jetski:Gemini
Cherry-pick from ag/43930329:

Use uint64_t for block counts and loop indices (j, blocks, hash_data_blocks) in hashtree_info::verify_tree (and update their format specifiers to PRIu64) so multiplications by padded_digest_length_ and FEC_BLOCKSIZE are evaluated in 64-bit arithmetic. Precompute curr_hash_offset, curr_data_offset, and hash_data_size as uint64_t, and check hash_data_size against PTRDIFF_MAX before allocating data_hashes so 32-bit targets return -1 cleanly rather than aborting.

Change-Id: If0915d7f64b4af1cc4fc8478b8b13fca01947fc7

Assisted-by: Jetski:Gemini
@adelva1984
adelva1984 requested a review from Databean November 18, 2026 22:15
@adelva1984
adelva1984 added this pull request to the merge queue Nov 19, 2026
Merged via the queue into google:main with commit e780630 Nov 19, 2026
76 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.

2 participants