Skip to content

Commit

Permalink
Don't allow possible negative values to wrap and become massive
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-allan committed Jul 9, 2024
1 parent 51d8ba7 commit 79c2305
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions omeroweb/webgateway/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3234,8 +3234,10 @@ def column_to_packed_bits(column):
"""
if len(column.values) > 0 and isinstance(column.values[0], float):
raise ValueError("Cannot have ID of float")
# Coerce strings to uint64 if required
indexes = numpy.array(column.values, dtype="uint64")
# Coerce strings to int64 if required. If we have values > 2**63 they
# wouldn't work anyway so signed is okay here. Note that the
# implementation does get weird if the indexes are negative values.
indexes = numpy.array(column.values, dtype="int64")
bits = numpy.zeros(int(indexes.max() + 1), dtype="uint8")
bits[indexes] = 1
return numpy.packbits(bits, bitorder="big").tobytes()
Expand Down

0 comments on commit 79c2305

Please sign in to comment.