Skip to content

HHH-19464 storing a binary data into blob on oracle cutting off its content #10160

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

cigaly
Copy link
Contributor

@cigaly cigaly commented May 15, 2025

Jira issue HHH-19464

In org.hibernate.type.descriptor.java.DataHelper#extractBytes(java.io.InputStream, long, int) assumption that java.io.InputStream#read(byte[]) reached EOF when number of bytes read is less than size of buffer is not correct.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


@cigaly cigaly changed the title Hhh 19464 storing a binary data into blob on oracle cutting off its content HHH-19464 storing a binary data into blob on oracle cutting off its content May 15, 2025

@Test
void hibernate_blob_streaming(SessionFactoryScope scope) throws Exception {
final var zipFilePath = getClass().getClassLoader().getResource( "org/hibernate/orm/test/lob/JarFileEntryBlobTest.zip" );
Copy link
Member

Choose a reason for hiding this comment

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

Not great (and potentially dangerous) to have a zip file just for testing purposes. Could we reproduce the error with a simple byte-array and org.hibernate.engine.jdbc.proxy.BlobProxy?

Copy link
Contributor Author

@cigaly cigaly May 19, 2025

Choose a reason for hiding this comment

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

Any stream that will always read complete buffer (with exception of last read) will not expose this problem. java.util.zip.InflaterInputStream can return less bytes before reading next bytes to be deflated.

Possible way to avoid zip file in resources is to create it temporary on th fly.

To avoid this GZIPOutputStream can be used to deflate (random) bytes, then GZIPInputStream can be used to create blob.

@cigaly cigaly force-pushed the HHH-19464-Storing_a_binary_data_into_BLOB_on_Oracle_cutting_off_its_content branch from a69a8b7 to baad677 Compare May 20, 2025 07:12
@cigaly cigaly force-pushed the HHH-19464-Storing_a_binary_data_into_BLOB_on_Oracle_cutting_off_its_content branch from baad677 to 0add274 Compare May 20, 2025 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants