[libpostgresql-jdbc-java] 03/11: When performing replace processing we must continue processing until we hit the end of a user supplied query, not just once we've detected the end of a valid query. Consider the example: SELECT a FROM t WHERE (1>0)) ORDER BY a; We must send the whole query to the backend, not just the section before the last closing parenthesis.

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:19:53 UTC 2017


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to tag REL8_1_406
in repository libpostgresql-jdbc-java.

commit dd554e3ba3a394d35afe5929c8d2941c6a41d173
Author: Kris Jurka <books at ejurka.com>
Date:   Sat Apr 29 00:07:02 2006 +0000

    When performing replace processing we must continue processing
    until we hit the end of a user supplied query, not just once
    we've detected the end of a valid query.  Consider the example:
    SELECT a FROM t WHERE (1>0)) ORDER BY a;
    We must send the whole query to the backend, not just the section
    before the last closing parenthesis.
    
    Reported by Senden Kris
---
 org/postgresql/core/PGStream.java             | 42 +++++++++++++++++++++++----
 org/postgresql/core/v2/QueryExecutorImpl.java | 20 +++++++++++--
 org/postgresql/core/v3/QueryExecutorImpl.java | 13 +++++++--
 org/postgresql/util/PSQLState.java            |  3 +-
 4 files changed, 66 insertions(+), 12 deletions(-)

diff --git a/org/postgresql/core/PGStream.java b/org/postgresql/core/PGStream.java
index c7dd8ae..16c8641 100644
--- a/org/postgresql/core/PGStream.java
+++ b/org/postgresql/core/PGStream.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2003-2005, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/core/PGStream.java,v 1.16 2005/06/25 00:53:15 oliver Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/core/PGStream.java,v 1.16.2.1 2005/12/02 03:06:01 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -356,7 +356,7 @@ public class PGStream
      * an array of bytearrays
      * @exception IOException if a data I/O error occurs
      */
-    public byte[][] ReceiveTupleV3() throws IOException
+    public byte[][] ReceiveTupleV3() throws IOException, OutOfMemoryError
     {
         //TODO: use l_msgSize
         int l_msgSize = ReceiveIntegerR(4);
@@ -364,13 +364,24 @@ public class PGStream
         int l_nf = ReceiveIntegerR(2);
         byte[][] answer = new byte[l_nf][];
 
+        OutOfMemoryError oom = null;
         for (i = 0 ; i < l_nf ; ++i)
         {
             int l_size = ReceiveIntegerR(4);
-            if (l_size != -1)
-                answer[i] = Receive(l_size);
+            if (l_size != -1) {
+                try {
+                    answer[i] = new byte[l_size];
+                    Receive(answer[i], 0, l_size);
+                } catch(OutOfMemoryError oome) {
+                    oom = oome;
+                    Skip(l_size);
+                }
+            }
         }
 
+        if (oom != null)
+            throw oom;
+
         return answer;
     }
 
@@ -385,7 +396,7 @@ public class PGStream
      * an array of bytearrays
      * @exception IOException if a data I/O error occurs
      */
-    public byte[][] ReceiveTupleV2(int nf, boolean bin) throws IOException
+    public byte[][] ReceiveTupleV2(int nf, boolean bin) throws IOException, OutOfMemoryError
     {
         int i, bim = (nf + 7) / 8;
         byte[] bitmask = Receive(bim);
@@ -394,6 +405,7 @@ public class PGStream
         int whichbit = 0x80;
         int whichbyte = 0;
 
+        OutOfMemoryError oom = null;
         for (i = 0 ; i < nf ; ++i)
         {
             boolean isNull = ((bitmask[whichbyte] & whichbit) == 0);
@@ -410,9 +422,19 @@ public class PGStream
                     len -= 4;
                 if (len < 0)
                     len = 0;
-                answer[i] = Receive(len);
+                try {
+                    answer[i] = new byte[len];
+                    Receive(answer[i], 0, len);
+                } catch(OutOfMemoryError oome) {
+                    oom = oome;
+                    Skip(len);
+                }
             }
         }
+
+        if (oom != null)
+            throw oom;
+
         return answer;
     }
 
@@ -451,6 +473,14 @@ public class PGStream
         }
     }
 
+    public void Skip(int size) throws IOException {
+        long s = 0;
+        while (s < size) {
+            s += pg_input.skip(size - s);
+        }
+    }
+
+
     /**
      * Copy data from an input stream to the connection.
      *
diff --git a/org/postgresql/core/v2/QueryExecutorImpl.java b/org/postgresql/core/v2/QueryExecutorImpl.java
index 72d07e9..d5ef574 100644
--- a/org/postgresql/core/v2/QueryExecutorImpl.java
+++ b/org/postgresql/core/v2/QueryExecutorImpl.java
@@ -4,7 +4,7 @@
 * Copyright (c) 2004, Open Cloud Limited.
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/core/v2/QueryExecutorImpl.java,v 1.13 2005/04/20 00:10:58 oliver Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/core/v2/QueryExecutorImpl.java,v 1.13.2.1 2005/12/15 23:28:51 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -421,7 +421,15 @@ public class QueryExecutorImpl implements QueryExecutor {
                     if (Driver.logDebug)
                         Driver.debug(" <=BE BinaryRow");
 
-                    Object tuple = pgStream.ReceiveTupleV2(fields.length, true);
+                    Object tuple = null;
+                    try {
+                        tuple = pgStream.ReceiveTupleV2(fields.length, true);
+                    } catch(OutOfMemoryError oome) {
+                        if (maxRows == 0 || tuples.size() < maxRows) {
+                            handler.handleError(new PSQLException(GT.tr("Ran out of memory retrieving query results."), PSQLState.OUT_OF_MEMORY, oome));
+                        }
+                    }
+
                     for (int i = 0; i < fields.length; i++)
                         fields[i].setFormat(Field.BINARY_FORMAT); //Set the field to binary format
                     if (maxRows == 0 || tuples.size() < maxRows)
@@ -455,7 +463,13 @@ public class QueryExecutorImpl implements QueryExecutor {
                     if (Driver.logDebug)
                         Driver.debug(" <=BE DataRow");
 
-                    Object tuple = pgStream.ReceiveTupleV2(fields.length, false);
+                    Object tuple = null;
+                    try {
+                        tuple = pgStream.ReceiveTupleV2(fields.length, false);
+                    } catch(OutOfMemoryError oome) {
+                        if (maxRows == 0 || tuples.size() < maxRows)
+                            handler.handleError(new PSQLException(GT.tr("Ran out of memory retrieving query results."), PSQLState.OUT_OF_MEMORY, oome));
+                    }
                     if (maxRows == 0 || tuples.size() < maxRows)
                         tuples.addElement(tuple);
                 }
diff --git a/org/postgresql/core/v3/QueryExecutorImpl.java b/org/postgresql/core/v3/QueryExecutorImpl.java
index 13aaeae..0550193 100644
--- a/org/postgresql/core/v3/QueryExecutorImpl.java
+++ b/org/postgresql/core/v3/QueryExecutorImpl.java
@@ -4,7 +4,7 @@
 * Copyright (c) 2004, Open Cloud Limited.
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/core/v3/QueryExecutorImpl.java,v 1.25 2005/11/05 09:27:13 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/core/v3/QueryExecutorImpl.java,v 1.25.2.1 2006/04/26 20:07:05 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -1283,7 +1283,16 @@ public class QueryExecutorImpl implements QueryExecutor {
                 break;
 
             case 'D':  // Data Transfer (ongoing Execute response)
-                Object tuple = pgStream.ReceiveTupleV3();
+                Object tuple = null;
+                try {
+                    tuple = pgStream.ReceiveTupleV3();
+                } catch(OutOfMemoryError oome) {
+                    if (!noResults) {
+                        handler.handleError(new PSQLException(GT.tr("Ran out of memory retrieving query results."), PSQLState.OUT_OF_MEMORY, oome));
+                    }
+                }
+
+
                 if (!noResults)
                 {
                     if (tuples == null)
diff --git a/org/postgresql/util/PSQLState.java b/org/postgresql/util/PSQLState.java
index 3ef5c7b..2aadcea 100644
--- a/org/postgresql/util/PSQLState.java
+++ b/org/postgresql/util/PSQLState.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2003-2005, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/util/PSQLState.java,v 1.8 2005/01/14 01:20:25 oliver Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/util/PSQLState.java,v 1.9 2005/01/15 07:53:03 oliver Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -71,6 +71,7 @@ public class PSQLState implements java.io.Serializable
     public final static PSQLState DATA_TYPE_MISMATCH = new PSQLState("42821");
     public final static PSQLState UNDEFINED_FUNCTION = new PSQLState("42883");
 
+    public final static PSQLState OUT_OF_MEMORY = new PSQLState("53200");
     public final static PSQLState OBJECT_NOT_IN_STATE = new PSQLState("55000");
 
     public final static PSQLState SYSTEM_ERROR = new PSQLState("60000");

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git



More information about the pkg-java-commits mailing list