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

BlobInputStream does not reset() to correct position if LargeObject was not at position 0. #3149

Open
OrangeDog opened this issue Feb 29, 2024 · 0 comments · May be fixed by #3148
Open

BlobInputStream does not reset() to correct position if LargeObject was not at position 0. #3149

OrangeDog opened this issue Feb 29, 2024 · 0 comments · May be fixed by #3148

Comments

@OrangeDog
Copy link
Contributor

Describe the issue
The InputStream created from a LargeObject starts from the current position of that object, but the mark and reset functions do not account for this.

Driver Version?
42.7.2

Java Version?
17.0.1

OS Version?
Windows 11

PostgreSQL Version?
14.10

To Reproduce

public class TestMarkReset {
    public static void main(String []args) throws Exception {
        String url = "jdbc:postgresql://localhost:5432/test";

        Properties props = new Properties();
        props.setProperty("user", "test");
        props.setProperty("password", "test");
        try ( Connection conn = DriverManager.getConnection(url, props) ){

            LargeObjectManager lom = ((PGConnection) con).getLargeObjectAPI();
            try (LargeObject blob = lom.open(123456)) {  // contains bytes in ascending order
                assertArrayEquals(new byte[]{0, 1, 2, 3}, blob.read(4));
                InputStream is = blob.getInputStream();
                is.mark(1);
                assertEquals(4, is.read());
                is.reset();
                assertEquals(4, is.read());  // FAILS: 4 != 0
            }

        }
    }
}

Expected behaviour
The stream returns to the marked position, regardless of how it was constructed.

@OrangeDog OrangeDog linked a pull request Feb 29, 2024 that will close this issue
9 tasks
OrangeDog added a commit to OrangeDog/pgjdbc that referenced this issue Mar 5, 2024
A BlobInputStream will start reading from the current position of the LargeObject used to create it, but the current/marked position does not account for this.
Initialising current position correctly will fix this.

Closes pgjdbc#3149
OrangeDog added a commit to OrangeDog/pgjdbc that referenced this issue May 13, 2024
A BlobInputStream will start reading from the current position of the LargeObject used to create it, but the current/marked position does not account for this.
Initialising current position correctly will fix this.

Closes pgjdbc#3149
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 a pull request may close this issue.

1 participant