Repository: GoogleCloudPlatform/pgadapter
Pull request #910 (2023-07-01 11:57:33)

fix: remove invalid BootstrapMessage length check
Remove the custom length check for BootstrapMessage class. This class marked messages with a length greater than 256 bytes as invalid, which is not correct.

This could cause a `java.lang.IllegalArgumentException: Invalid bootstrap message length: <length>`
error to be thrown.


Patch:
diff --git a/pom.xml b/pom.xml
index 3e679753..4dbfaa7d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -76,7 +76,7 @@
     <dependency>
       <groupId>com.google.auto.value</groupId>
       <artifactId>auto-value-annotations</artifactId>
-      <version>1.10.1</version>
+      <version>1.10.2</version>
     </dependency>
     <dependency>
       <groupId>org.checkerframework</groupId>
@@ -127,7 +127,7 @@
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-model</artifactId>
-      <version>3.9.2</version>
+      <version>3.9.3</version>
     </dependency>
     <dependency>
       <groupId>org.bouncycastle</groupId>
diff --git a/samples/golang/gorm/go.mod b/samples/golang/gorm/go.mod
index 46676c55..91b37fb2 100644
--- a/samples/golang/gorm/go.mod
+++ b/samples/golang/gorm/go.mod
@@ -7,7 +7,7 @@ require (
 	github.com/shopspring/decimal v1.3.1
 	gorm.io/datatypes v1.2.0
 	gorm.io/driver/postgres v1.5.2
-	gorm.io/gorm v1.25.1
+	gorm.io/gorm v1.25.2
 )
 
 require (
diff --git a/samples/golang/gorm/go.sum b/samples/golang/gorm/go.sum
index 347cdfff..ce116033 100644
--- a/samples/golang/gorm/go.sum
+++ b/samples/golang/gorm/go.sum
@@ -142,5 +142,5 @@ gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
 gorm.io/gorm v1.24.0/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=
 gorm.io/gorm v1.24.7-0.20230306060331-85eaf9eeda11/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
 gorm.io/gorm v1.25.0/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
-gorm.io/gorm v1.25.1 h1:nsSALe5Pr+cM3V1qwwQ7rOkw+6UeLrX5O4v3llhHa64=
-gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
+gorm.io/gorm v1.25.2 h1:gs1o6Vsa+oVKG/a9ElL3XgyGfghFfkKA2SInQaCyMho=
+gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
diff --git a/samples/java/liquibase/pom.xml b/samples/java/liquibase/pom.xml
index 0e1d6b4f..c180da92 100644
--- a/samples/java/liquibase/pom.xml
+++ b/samples/java/liquibase/pom.xml
@@ -62,7 +62,7 @@
         <plugin>
           <groupId>org.liquibase</groupId>
           <artifactId>liquibase-maven-plugin</artifactId>
-          <version>4.22.0</version>
+          <version>4.23.0</version>
           <configuration>
             <propertyFile>liquibase.properties</propertyFile>
             <outputChangeLogFile>changelog-master.xml</outputChangeLogFile>
diff --git a/src/main/java/com/google/cloud/spanner/pgadapter/wireprotocol/BootstrapMessage.java b/src/main/java/com/google/cloud/spanner/pgadapter/wireprotocol/BootstrapMessage.java
index e4ac643e..2a02bf40 100644
--- a/src/main/java/com/google/cloud/spanner/pgadapter/wireprotocol/BootstrapMessage.java
+++ b/src/main/java/com/google/cloud/spanner/pgadapter/wireprotocol/BootstrapMessage.java
@@ -37,8 +37,6 @@ import java.util.Map;
  */
 @InternalApi
 public abstract class BootstrapMessage extends WireMessage {
-  private static final int MAX_BOOTSTRAP_MESSAGE_LENGTH = 1 << 8;
-
   public BootstrapMessage(ConnectionHandler connection, int length) {
     super(connection, length);
   }
@@ -53,9 +51,6 @@ public abstract class BootstrapMessage extends WireMessage {
    */
   public static BootstrapMessage create(ConnectionHandler connection) throws Exception {
     int length = connection.getConnectionMetadata().getInputStream().readInt();
-    if (length > MAX_BOOTSTRAP_MESSAGE_LENGTH) {
-      throw new IllegalArgumentException("Invalid bootstrap message length: " + length);
-    }
     int protocol = connection.getConnectionMetadata().getInputStream().readInt();
     switch (protocol) {
       case SSLMessage.IDENTIFIER:


Test patch:
diff --git a/src/test/golang/pgadapter_gorm_tests/go.mod b/src/test/golang/pgadapter_gorm_tests/go.mod
index 09bf1c16..a6b5d2fe 100644
--- a/src/test/golang/pgadapter_gorm_tests/go.mod
+++ b/src/test/golang/pgadapter_gorm_tests/go.mod
@@ -6,7 +6,7 @@ require (
 	github.com/shopspring/decimal v1.3.1
 	gorm.io/datatypes v1.2.0
 	gorm.io/driver/postgres v1.5.2
-	gorm.io/gorm v1.25.1
+	gorm.io/gorm v1.25.2
 )
 
 require (
diff --git a/src/test/golang/pgadapter_gorm_tests/go.sum b/src/test/golang/pgadapter_gorm_tests/go.sum
index 3561349d..43f01533 100644
--- a/src/test/golang/pgadapter_gorm_tests/go.sum
+++ b/src/test/golang/pgadapter_gorm_tests/go.sum
@@ -141,5 +141,5 @@ gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
 gorm.io/gorm v1.24.0/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=
 gorm.io/gorm v1.24.7-0.20230306060331-85eaf9eeda11/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
 gorm.io/gorm v1.25.0/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
-gorm.io/gorm v1.25.1 h1:nsSALe5Pr+cM3V1qwwQ7rOkw+6UeLrX5O4v3llhHa64=
-gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
+gorm.io/gorm v1.25.2 h1:gs1o6Vsa+oVKG/a9ElL3XgyGfghFfkKA2SInQaCyMho=
+gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
diff --git a/src/test/java/com/google/cloud/spanner/pgadapter/wireprotocol/BoostrapMessageTest.java b/src/test/java/com/google/cloud/spanner/pgadapter/wireprotocol/BoostrapMessageTest.java
new file mode 100644
index 00000000..0f0a66b7
--- /dev/null
+++ b/src/test/java/com/google/cloud/spanner/pgadapter/wireprotocol/BoostrapMessageTest.java
@@ -0,0 +1,60 @@
+// Copyright 2023 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.cloud.spanner.pgadapter.wireprotocol;
+
+import static junit.framework.TestCase.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.google.cloud.spanner.pgadapter.ConnectionHandler;
+import com.google.cloud.spanner.pgadapter.ProxyServer;
+import com.google.cloud.spanner.pgadapter.metadata.ConnectionMetadata;
+import com.google.cloud.spanner.pgadapter.metadata.OptionsMetadata;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class BoostrapMessageTest {
+
+  @Test
+  public void testCreate() throws Exception {
+    ConnectionHandler connection = mock(ConnectionHandler.class);
+    ProxyServer server = mock(ProxyServer.class);
+    when(connection.getServer()).thenReturn(server);
+    OptionsMetadata options = mock(OptionsMetadata.class);
+    when(server.getOptions()).thenReturn(options);
+    ConnectionMetadata metadata = mock(ConnectionMetadata.class);
+    when(connection.getConnectionMetadata()).thenReturn(metadata);
+    PipedInputStream pipedInputStream = new PipedInputStream(2048);
+    DataInputStream dataInputStream = new DataInputStream(pipedInputStream);
+    when(metadata.getInputStream()).thenReturn(dataInputStream);
+    DataOutputStream dataOutputStream =
+        new DataOutputStream(new PipedOutputStream(pipedInputStream));
+    // length
+    dataOutputStream.writeInt(1024);
+    // identifier
+    dataOutputStream.writeInt(StartupMessage.IDENTIFIER);
+    dataOutputStream.write(new byte[1024]);
+
+    BootstrapMessage message = BootstrapMessage.create(connection);
+    assertEquals(StartupMessage.class, message.getClass());
+    assertEquals(message.length, 1024);
+  }
+}