Skip to content

Commit

Permalink
Large JSON and GEOMETRY objects h2database#3016
Browse files Browse the repository at this point in the history
push the check for large sizes down to minimise unwanted changes to other types
  • Loading branch information
grandinj committed Nov 25, 2021
1 parent 9ee083f commit 0bed95c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
4 changes: 2 additions & 2 deletions h2/src/main/org/h2/value/DataType.java
Expand Up @@ -312,8 +312,8 @@ private static DataType createGeometry() {
dataType.prefix = "'";
dataType.suffix = "'";
dataType.params = "TYPE,SRID";
dataType.maxPrecision = Constants.MAX_STRING_LENGTH;
dataType.defaultPrecision = Constants.MAX_STRING_LENGTH;
dataType.maxPrecision = Long.MAX_VALUE;
dataType.defaultPrecision = Long.MAX_VALUE;
return dataType;
}

Expand Down
9 changes: 8 additions & 1 deletion h2/src/main/org/h2/value/ValueBinary.java
Expand Up @@ -6,8 +6,10 @@
package org.h2.value;

import java.nio.charset.StandardCharsets;

import org.h2.engine.Constants;
import org.h2.engine.SysProperties;
import org.h2.message.DbException;
import org.h2.util.StringUtils;
import org.h2.util.Utils;

/**
Expand All @@ -22,6 +24,11 @@ public final class ValueBinary extends ValueBytesBase {

protected ValueBinary(byte[] value) {
super(value);
int length = value.length;
if (length > Constants.MAX_STRING_LENGTH) {
throw DbException.getValueTooLongException(getTypeName(getValueType()),
StringUtils.convertBytesToHex(value, 41), length);
}
}

/**
Expand Down
5 changes: 0 additions & 5 deletions h2/src/main/org/h2/value/ValueBytesBase.java
Expand Up @@ -30,11 +30,6 @@ abstract class ValueBytesBase extends Value {
int hash;

ValueBytesBase(byte[] value) {
int length = value.length;
if (length > Constants.MAX_STRING_LENGTH) {
throw DbException.getValueTooLongException(getTypeName(getValueType()),
StringUtils.convertBytesToHex(value, 41), length);
}
this.value = value;
}

Expand Down
7 changes: 7 additions & 0 deletions h2/src/main/org/h2/value/ValueJavaObject.java
Expand Up @@ -6,8 +6,10 @@
package org.h2.value;

import org.h2.api.ErrorCode;
import org.h2.engine.Constants;
import org.h2.engine.SysProperties;
import org.h2.message.DbException;
import org.h2.util.StringUtils;
import org.h2.util.Utils;

/**
Expand All @@ -19,6 +21,11 @@ public final class ValueJavaObject extends ValueBytesBase {

protected ValueJavaObject(byte[] v) {
super(v);
int length = value.length;
if (length > Constants.MAX_STRING_LENGTH) {
throw DbException.getValueTooLongException(getTypeName(getValueType()),
StringUtils.convertBytesToHex(value, 41), length);
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions h2/src/main/org/h2/value/ValueJson.java
Expand Up @@ -11,6 +11,7 @@
import java.util.Arrays;

import org.h2.api.ErrorCode;
import org.h2.engine.Constants;
import org.h2.message.DbException;
import org.h2.util.StringUtils;
import org.h2.util.json.JSONByteArrayTarget;
Expand Down Expand Up @@ -50,6 +51,11 @@ public final class ValueJson extends ValueBytesBase {

private ValueJson(byte[] value) {
super(value);
int length = value.length;
if (length > Constants.MAX_STRING_LENGTH) {
throw DbException.getValueTooLongException(getTypeName(getValueType()),
StringUtils.convertBytesToHex(value, 41), length);
}
}

@Override
Expand Down
9 changes: 8 additions & 1 deletion h2/src/main/org/h2/value/ValueVarbinary.java
Expand Up @@ -6,8 +6,10 @@
package org.h2.value;

import java.nio.charset.StandardCharsets;

import org.h2.engine.Constants;
import org.h2.engine.SysProperties;
import org.h2.message.DbException;
import org.h2.util.StringUtils;
import org.h2.util.Utils;

/**
Expand All @@ -27,6 +29,11 @@ public final class ValueVarbinary extends ValueBytesBase {

protected ValueVarbinary(byte[] value) {
super(value);
int length = value.length;
if (length > Constants.MAX_STRING_LENGTH) {
throw DbException.getValueTooLongException(getTypeName(getValueType()),
StringUtils.convertBytesToHex(value, 41), length);
}
}

/**
Expand Down

0 comments on commit 0bed95c

Please sign in to comment.