Skip to content

Missing null check when parsing unverified SHA1 #553

@mshandrovskiy

Description

@mshandrovskiy

if content_sha1.startswith(UNVERIFIED_CHECKSUM_PREFIX):

This function is invoked in context where content_sha1 is typed as str | None. This code will crash on None input.

content_sha1: str | None,

Simple test output with just related code copypasta into my own test runner.

Traceback (most recent call last):
  File "/Users/mikes/PycharmProjects/account-api/tests/testing.py", line 147, in wrapper
    return self.loop.run_until_complete(coro)
  File "/Users/mikes/.pyenv/versions/3.6.12/lib/python3.6/asyncio/base_events.py", line 488, in run_until_complete
    return future.result()
  File "/Users/mikes/PycharmProjects/account-api/tests/test_storage_providers.py", line 84, in test_b2_object_attr_sha1_unset
    result = await self.b2_provider.get_object_metadata('key', photo)
  File "/Users/mikes/PycharmProjects/account-api/accounts/files/v4_1/providers.py", line 167, in get_object_metadata
    if sha1.startswith(UNVERIFIED_CHECKSUM_PREFIX):
AttributeError: 'NoneType' object has no attribute 'startswith'

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions