From f644b48363d893c9ee41fee3752936cd6c511756 Mon Sep 17 00:00:00 2001 From: injectives <11927660+injectives@users.noreply.github.com> Date: Thu, 7 Jul 2022 12:32:39 +0100 Subject: [PATCH] Do not allow mixing UTC and legacy datetime and throw ProtocolException on unknown struct types (#1260) --- .../messaging/common/CommonValueUnpacker.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/driver/src/main/java/org/neo4j/driver/internal/messaging/common/CommonValueUnpacker.java b/driver/src/main/java/org/neo4j/driver/internal/messaging/common/CommonValueUnpacker.java index e7534da0e0..6df8bc5674 100644 --- a/driver/src/main/java/org/neo4j/driver/internal/messaging/common/CommonValueUnpacker.java +++ b/driver/src/main/java/org/neo4j/driver/internal/messaging/common/CommonValueUnpacker.java @@ -39,6 +39,7 @@ import java.util.Map; import org.neo4j.driver.Value; import org.neo4j.driver.exceptions.ClientException; +import org.neo4j.driver.exceptions.ProtocolException; import org.neo4j.driver.internal.InternalNode; import org.neo4j.driver.internal.InternalPath; import org.neo4j.driver.internal.InternalRelationship; @@ -188,21 +189,29 @@ protected Value unpackStruct(long size, byte type) throws IOException { if (!dateTimeUtcEnabled) { ensureCorrectStructSize(TypeConstructor.DATE_TIME, DATE_TIME_STRUCT_SIZE, size); return unpackDateTimeWithZoneOffset(); + } else { + throw instantiateExceptionForUnknownType(type); } case DATE_TIME_WITH_ZONE_OFFSET_UTC: if (dateTimeUtcEnabled) { ensureCorrectStructSize(TypeConstructor.DATE_TIME, DATE_TIME_STRUCT_SIZE, size); return unpackDateTimeUtcWithZoneOffset(); + } else { + throw instantiateExceptionForUnknownType(type); } case DATE_TIME_WITH_ZONE_ID: if (!dateTimeUtcEnabled) { ensureCorrectStructSize(TypeConstructor.DATE_TIME, DATE_TIME_STRUCT_SIZE, size); return unpackDateTimeWithZoneId(); + } else { + throw instantiateExceptionForUnknownType(type); } case DATE_TIME_WITH_ZONE_ID_UTC: if (dateTimeUtcEnabled) { ensureCorrectStructSize(TypeConstructor.DATE_TIME, DATE_TIME_STRUCT_SIZE, size); return unpackDateTimeUtcWithZoneId(); + } else { + throw instantiateExceptionForUnknownType(type); } case DURATION: ensureCorrectStructSize(TypeConstructor.DURATION, DURATION_TIME_STRUCT_SIZE, size); @@ -224,7 +233,7 @@ protected Value unpackStruct(long size, byte type) throws IOException { ensureCorrectStructSize(TypeConstructor.PATH, 3, size); return unpackPath(); default: - throw new IOException("Unknown struct type: " + type); + throw instantiateExceptionForUnknownType(type); } } @@ -417,4 +426,8 @@ private ZonedDateTime newZonedDateTimeUsingUtcBaseline(long epochSecondLocal, in LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zoneId); return ZonedDateTime.of(localDateTime, zoneId); } + + private ProtocolException instantiateExceptionForUnknownType(byte type) { + return new ProtocolException("Unknown struct type: " + type); + } }