apache / apache/geaflow

Math.abs(Integer.MIN_VALUE) will overflow and return a negative value

Open
#758 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
808
Forks
188
Avg merge
3d 22h
Merged PRs (30d)
2

Description

**Describe the bug**

[Substr.java](https://github.com/apache/geaflow/blob/main/geaflow/geaflow-dsl/geaflow-dsl-plan/src/main/java/org/apache/geaflow/dsl/udf/table/string/Substr.java#L34-L36)

```java
if ((Math.abs(pos) > str.length())) {
return str;
}
```
**Expected behavior**

Math.abs(Integer.MIN_VALUE) will overflow
return a negative value

Contributor guide

Open the contributing guide

Research direction

Start by reading geaflow/geaflow-dsl/geaflow-dsl-plan/src/main/java/org/apache/geaflow/dsl/udf/table/string/Substr.java at lines 34-36, focusing on how the position bound is checked. Reproduce the Integer.MIN_VALUE case and verify that the bounds check no longer produces an incorrect negative result while existing substring behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.