Skip to content

Conversation

@iroqueta
Copy link
Collaborator

@iroqueta iroqueta commented Jul 4, 2025

… could cause out of memory errors.

Now the process use a buffer to avoid this.
Issue: 205339

… could cause out of memory errors.

Now the process use a buffer to avoid this.
Issue: 205339
@iroqueta iroqueta requested a review from ladrians July 4, 2025 19:34
@genexusbot
Copy link
Collaborator

Cherry pick to beta success

… could cause out of memory errors.

Now the process use a buffer to avoid this.
Issue: 205339
@genexusbot
Copy link
Collaborator

Cherry pick to beta success

Copy link

@ladrians ladrians left a comment

Choose a reason for hiding this comment

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

lgtm!

iroqueta and others added 2 commits July 11, 2025 11:11
…rage. Previously, if the file extension was .tmp, it was always set to image/jpeg, which caused issues—such as when uploading a PDF: upon downloading it, the file couldn't be opened properly.
@genexusbot
Copy link
Collaborator

Cherry pick to beta failed, 1 conflicted file in commit e131aea
  • wrappercommon/pom.xml

Copy link

@ladrians ladrians left a comment

Choose a reason for hiding this comment

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

this time I checked the usage of detectedContentType for the assignment of "image/jpeg", looks good

@genexusbot
Copy link
Collaborator

Manual cherry pick to beta success

@genexusbot
Copy link
Collaborator

Cherry pick to beta failed, 2 conflicted files in commit e131aea
  • gxcloudstorage-common/pom.xml
  • wrappercommon/pom.xml

@tomas-sexenian tomas-sexenian requested review from Copilot and removed request for Copilot July 21, 2025 18:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses memory issues in file upload methods by replacing in-memory byte array operations with streaming operations to prevent out-of-memory errors when handling large files. The change introduces a new helper utility to process InputStreams using temporary files and buffers.

  • Replaces in-memory byte array conversion with buffered streaming for all cloud storage providers
  • Introduces a new helper class to handle InputStream processing with content type detection
  • Removes unused commons-io dependencies from modules that no longer need them

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
gxcloudstorage-common/src/main/java/com/genexus/db/driver/ExternalProviderHelper.java Adds new helper method for streaming InputStreams with content type detection
gxcloudstorage-ibmcos/src/main/java/com/genexus/db/driver/ExternalProviderIBM.java Replaces byte array conversion with streaming upload
gxcloudstorage-googlecloudstorage/src/main/java/com/genexus/db/driver/ExternalProviderGoogle.java Updates upload method to use streaming approach
gxcloudstorage-azureblob/src/main/java/com/genexus/db/driver/ExternalProviderAzureStorage.java Improves buffering and uses helper for content type detection
gxcloudstorage-awss3-v2/src/main/java/com/genexus/db/driver/ExternalProviderS3V2.java Replaces ByteBuffer approach with streaming
gxcloudstorage-awss3-v1/src/main/java/com/genexus/db/driver/ExternalProviderS3V1.java Updates to use streaming instead of byte arrays
common/src/main/java/com/genexus/util/GXFileInfo.java Adds streaming method to avoid loading entire file into memory
Multiple pom.xml files Updates dependencies and removes unused commons-io references

}

public static InputStreamWithLength getInputStreamContentLength(InputStream input) throws IOException {
File tempFile = File.createTempFile("upload-", ".tmp");
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

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

Creating temporary files without specifying a secure directory could create files in a world-readable location. Consider using a secure temporary directory or setting appropriate file permissions.

Suggested change
File tempFile = File.createTempFile("upload-", ".tmp");
File tempFile = File.createTempFile("upload-", ".tmp");
tempFile.setReadable(false, false); // Disable read for all users
tempFile.setWritable(false, false); // Disable write for all users
tempFile.setExecutable(false, false); // Disable execute for all users
tempFile.setReadable(true, true); // Enable read for owner only
tempFile.setWritable(true, true); // Enable write for owner only

Copilot uses AI. Check for mistakes.
return value;
}

public static InputStreamWithLength getInputStreamContentLength(InputStream input) throws IOException {
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

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

If an exception occurs after creating the temporary file but before returning the InputStreamWithLength, the temporary file will not be cleaned up, causing a resource leak. Consider adding a try-catch block to clean up the temp file on error.

Copilot uses AI. Check for mistakes.
byte[] targetArray = IOUtils.toByteArray(input);
storageClient.create(blobInfo, targetArray);

storageClient.createFrom(blobInfo, streamInfo.tempFile.toPath());
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

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

There's no null check for streamInfo.tempFile before calling toPath(). If the helper method fails to create a temp file, this could result in a NullPointerException.

Copilot uses AI. Check for mistakes.
@genexusbot
Copy link
Collaborator

Manual cherry pick to beta success

@genexusbot
Copy link
Collaborator

Cherry pick to beta failed, 2 conflicted files in commit e131aea
  • gxcloudstorage-common/pom.xml
  • wrappercommon/pom.xml

@genexusbot
Copy link
Collaborator

Manual cherry pick to beta success

@genexusbot
Copy link
Collaborator

Cherry pick to beta failed, 4 conflicted files in commit e131aea
  • gxcloudstorage-azureblob/src/main/java/com/genexus/db/driver/ExternalProviderAzureStorage.java
  • gxcloudstorage-common/pom.xml
  • gxcloudstorage-common/src/main/java/com/genexus/db/driver/ExternalProviderHelper.java
  • wrappercommon/pom.xml

@iroqueta iroqueta merged commit 1fa5ad3 into master Jul 23, 2025
9 of 10 checks passed
@iroqueta iroqueta deleted the CreateFileFromStream branch July 23, 2025 20:14
iroqueta added a commit that referenced this pull request Jul 23, 2025
#980)

* The method createNewFile converts all the inputstream to memory. This could cause out of memory errors.
Now the process use a buffer to avoid this.
Issue: 205339

* The method createNewFile converts all the inputstream to memory. This could cause out of memory errors.
Now the process use a buffer to avoid this.
Issue: 205339

* Tries to determine the content-type of files uploaded to external storage. Previously, if the file extension was .tmp, it was always set to image/jpeg, which caused issues—such as when uploading a PDF: upon downloading it, the file couldn't be opened properly.

* Update Tika version to be java 8 compliant.

* Add log4j impl for slf4j to avoid "No SLF4J providers were found" in Tika logs

* Implemented better way to delete temporary files

(cherry picked from commit 1fa5ad3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants