Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Explicitly cast upload memory size config values to integers #1138

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions codecov/settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,11 @@
IS_ENTERPRISE = get_settings_module() == SettingsModule.ENTERPRISE.value
IS_DEV = get_settings_module() == SettingsModule.DEV.value

DATA_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "upload_max_memory_size", default=2621440
DATA_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "upload_max_memory_size", default=2621440)
Comment on lines 347 to +349
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change. Converting the configuration value to an integer ensures type consistency and prevents potential issues with non-integer values. However, consider adding error handling in case the conversion fails.

Suggested change
DATA_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "upload_max_memory_size", default=2621440
DATA_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "upload_max_memory_size", default=2621440)
DATA_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "upload_max_memory_size", default=2621440)
)
try:
DATA_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "upload_max_memory_size", default=2621440)
)
except ValueError:
DATA_UPLOAD_MAX_MEMORY_SIZE = 2621440 # Default value if conversion fails
logging.warning("Invalid value for DATA_UPLOAD_MAX_MEMORY_SIZE. Using default.")

)
FILE_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "file_upload_max_memory_size", default=2621440
FILE_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "file_upload_max_memory_size", default=2621440)
Comment on lines 350 to +352
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the previous comment, this is a good change for type consistency. Consider applying the same error handling approach here as well.

Suggested change
)
FILE_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "file_upload_max_memory_size", default=2621440
FILE_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "file_upload_max_memory_size", default=2621440)
FILE_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "file_upload_max_memory_size", default=2621440)
)
try:
FILE_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "file_upload_max_memory_size", default=2621440)
)
except ValueError:
FILE_UPLOAD_MAX_MEMORY_SIZE = 2621440 # Default value if conversion fails
logging.warning("Invalid value for FILE_UPLOAD_MAX_MEMORY_SIZE. Using default.")

Comment on lines 347 to +352
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment explaining why these values are being explicitly converted to integers. This will help future developers understand the reasoning behind the change.

Suggested change
DATA_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "upload_max_memory_size", default=2621440
DATA_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "upload_max_memory_size", default=2621440)
)
FILE_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "file_upload_max_memory_size", default=2621440
FILE_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "file_upload_max_memory_size", default=2621440)
# Explicitly convert upload size limits to integers to ensure type consistency
# and prevent issues with non-integer values from configuration
DATA_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "upload_max_memory_size", default=2621440)
)
FILE_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "file_upload_max_memory_size", default=2621440)
)

Comment on lines 347 to +352
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These configuration values are critical for controlling upload sizes. Consider adding validation to ensure the values are within an acceptable range to prevent potential security issues or resource exhaustion.

Suggested change
DATA_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "upload_max_memory_size", default=2621440
DATA_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "upload_max_memory_size", default=2621440)
)
FILE_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "file_upload_max_memory_size", default=2621440
FILE_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "file_upload_max_memory_size", default=2621440)
def validate_upload_size(size, min_size=1024, max_size=10485760):
if min_size <= size <= max_size:
return size
return max_size # Or min_size, depending on your preference
DATA_UPLOAD_MAX_MEMORY_SIZE = validate_upload_size(int(
get_config("setup", "http", "upload_max_memory_size", default=2621440)
))
FILE_UPLOAD_MAX_MEMORY_SIZE = validate_upload_size(int(
get_config("setup", "http", "file_upload_max_memory_size", default=2621440)
))

)

CORS_ALLOWED_ORIGIN_REGEXES = get_config(
Expand Down