Skip to content

Commit bec8d3d

Browse files
author
Lukas Bolz
committed
fix: issue#44 integer overflow in usage request
- `Usage.Detail::count` and `Usage.Detail::limit` were declared as `long` but parsed as `int`. - This seems to be caused by a176b6d, where the type was changed from `int` to `long` without adjusting the parsing. - This caused an integer overflow, resulting in a negative value when e.g. the character limit exceeded `Integer::MAX_VAlUE`.
1 parent 6fb600c commit bec8d3d

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

deepl-java/src/main/java/com/deepl/api/parsing/Parser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public String parseErrorMessage(String json) {
7676
return jsonObject.get(parameterName).getAsInt();
7777
}
7878

79+
static @Nullable Long getAsLongOrNull(JsonObject jsonObject, String parameterName) {
80+
if (!jsonObject.has(parameterName)) return null;
81+
return jsonObject.get(parameterName).getAsLong();
82+
}
83+
7984
static @Nullable String getAsStringOrNull(JsonObject jsonObject, String parameterName) {
8085
if (!jsonObject.has(parameterName)) return null;
8186
return jsonObject.get(parameterName).getAsString();

deepl-java/src/main/java/com/deepl/api/parsing/UsageDeserializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public Usage deserialize(JsonElement json, Type typeOfT, JsonDeserializationCont
2525
}
2626

2727
public static @Nullable Usage.Detail createDetail(JsonObject jsonObject, String prefix) {
28-
Integer count = Parser.getAsIntOrNull(jsonObject, prefix + "count");
29-
Integer limit = Parser.getAsIntOrNull(jsonObject, prefix + "limit");
28+
Long count = Parser.getAsLongOrNull(jsonObject, prefix + "count");
29+
Long limit = Parser.getAsLongOrNull(jsonObject, prefix + "limit");
3030
if (count == null || limit == null) return null;
3131
return new Usage.Detail(count, limit);
3232
}

0 commit comments

Comments
 (0)