Skip to content

Commit

Permalink
flatpak-prune: Make sure to calculate hash in the unsigned domain
Browse files Browse the repository at this point in the history
Otherwise, an out-of-bounds left shift can occur, as diagnosed by
UBSan here:

    ../../../../src/flatpak/common/flatpak-prune.c:387:14: runtime error: left shift of 253 by 24 places cannot be represented in type 'int'

Signed-off-by: Simon McVittie <[email protected]>
  • Loading branch information
smcv committed Mar 20, 2024
1 parent 56438bf commit 6dba822
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions common/flatpak-prune.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,10 @@ flatpak_ostree_object_name_hash (gconstpointer a)
those are the ones that will be first compared on a hash collision,
so if they were always the same that would waste 4 comparisons. */
return
data[32] |
data[31] << 8 |
data[30] << 16 |
data[29] << 24;
((guint32) data[32]) |
((guint32) data[31]) << 8 |
((guint32) data[30]) << 16 |
((guint32) data[29]) << 24;
}

static gboolean
Expand Down

0 comments on commit 6dba822

Please sign in to comment.