You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-issues@hadoop.apache.org by "Anton Kutuzov (Jira)" <ji...@apache.org> on 2023/06/09 06:35:00 UTC

[jira] [Commented] (HDFS-16029) Divide by zero bug in InstrumentationService.java

    [ https://issues.apache.org/jira/browse/HDFS-16029?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17730831#comment-17730831 ] 

Anton Kutuzov commented on HDFS-16029:
--------------------------------------

More precisely, we get an exception: ArrayIndexOutOfBoundsException, because before devizion use last as index of array:
{code:java}
.....
values[LAST_TOTAL] = total[last];
values[LAST_OWN] = own[last];
..... {code}
So this code will thow ArrayIndexOutOfBoundsException:
{code:java}
InstrumentationService.Timer timer = new InstrumentationService.Timer(2);
long[] values = timer.getValues(); {code}
and this
{code:java}
InstrumentationService.Timer timer = new InstrumentationService.Timer(2);
long[] values = timer.getJSON(); 

{code}
I propose to add check on -1 in getValues
{code:java}
long[] values = new long[4];
if (last < 0) {
  return valuse;
}
values[LAST_TOTAL] = total[last];
values[LAST_OWN] = own[last]; {code}

> Divide by zero bug in InstrumentationService.java
> -------------------------------------------------
>
>                 Key: HDFS-16029
>                 URL: https://issues.apache.org/jira/browse/HDFS-16029
>             Project: Hadoop HDFS
>          Issue Type: Bug
>          Components: libhdfs
>            Reporter: Yiyuan GUO
>            Priority: Major
>              Labels: easy-fix, security
>
> In the file _lib/service/instrumentation/InstrumentationService.java,_ the method 
>  _Timer.getValues_ has the following [code|https://github.com/apache/hadoop/blob/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/service/instrumentation/InstrumentationService.java#L236]:
> {code:java}
> long[] getValues() {
>     ......
>     int limit = (full) ? size : (last + 1);
>     ......
>     values[AVG_TOTAL] = values[AVG_TOTAL] / limit;
> }
> {code}
> The variable _limit_ is used as a divisor. However, its value may be equal to _last + 1,_ which can be zero since _last_ is initialized to -1 in the [constructor|https://github.com/apache/hadoop/blob/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/service/instrumentation/InstrumentationService.java#L222]:
> {code:java}
> public Timer(int size) {
>     ...
>     last = -1;
> }
> {code}
> Thus, a divide by zero problem can happen.
>   



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: hdfs-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: hdfs-issues-help@hadoop.apache.org