From 30b964d3d33a0e9bb17b0d8693316f9fb00328a3 Mon Sep 17 00:00:00 2001 From: James Mudd Date: Fri, 13 Dec 2024 18:16:17 +0000 Subject: [PATCH] Fix bug calculating buffer size with non-ascii chars --- jhdf/src/main/java/io/jhdf/object/datatype/StringData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jhdf/src/main/java/io/jhdf/object/datatype/StringData.java b/jhdf/src/main/java/io/jhdf/object/datatype/StringData.java index fa204a1b..c6094e07 100644 --- a/jhdf/src/main/java/io/jhdf/object/datatype/StringData.java +++ b/jhdf/src/main/java/io/jhdf/object/datatype/StringData.java @@ -167,7 +167,7 @@ public void setBufferLimit(ByteBuffer byteBuffer) { public static StringData create(Object data) { int maxLength = Arrays.stream(Utils.flatten(data)) .map(String.class::cast) - .mapToInt(String::length) + .mapToInt(s -> StandardCharsets.UTF_8.encode(s).limit()) .max().getAsInt(); return new StringData(PaddingType.NULL_TERMINATED, StandardCharsets.UTF_8, maxLength);