Thanks to visit codestin.com
Credit goes to github.com

Skip to content

createOriginalFileFromFileObj reads entire file into memory for SHA1 hash #479

@titusz

Description

@titusz

Problem

The method _BlitzGateway.createOriginalFileFromFileObj in src/omero/gateway/__init__.py line 4075 reads the entire file into memory to compute the SHA1 hash:

h.update(fo.read())  # Reads entire file into memory

This causes out-of-memory errors for files larger than available RAM.

Suggested Fix

Use chunked reading for SHA1 computation, similar to the upload logic that already uses 10KB chunks (lines 4093-4101):

h = sha1()
chunk_size = 10000
fo.seek(0)
while True:
    chunk = fo.read(chunk_size)
    if not chunk:
        break
    h.update(chunk)

Impact

Files larger than RAM cannot be uploaded through this method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions