From hdfs-issues-return-252679-archive-asf-public=cust-asf.ponee.io@hadoop.apache.org Fri Feb 22 01:10:04 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 9C0B318064C for ; Fri, 22 Feb 2019 02:10:03 +0100 (CET) Received: (qmail 31779 invoked by uid 500); 22 Feb 2019 01:10:02 -0000 Mailing-List: contact hdfs-issues-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list hdfs-issues@hadoop.apache.org Received: (qmail 31767 invoked by uid 99); 22 Feb 2019 01:10:02 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Feb 2019 01:10:02 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 156FCC290E for ; Fri, 22 Feb 2019 01:10:02 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -109.501 X-Spam-Level: X-Spam-Status: No, score=-109.501 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id oliuzE1IWs0r for ; Fri, 22 Feb 2019 01:10:01 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id B9B085F402 for ; Fri, 22 Feb 2019 01:10:00 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 5CEE8E00C9 for ; Fri, 22 Feb 2019 01:10:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 1B7CB24530 for ; Fri, 22 Feb 2019 01:10:00 +0000 (UTC) Date: Fri, 22 Feb 2019 01:10:00 +0000 (UTC) From: "Wei-Chiu Chuang (JIRA)" To: hdfs-issues@hadoop.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (HDFS-14285) libhdfs hdfsRead copies entire array even if its only partially filled MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/HDFS-14285?page=3Dcom.atlassian= .jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D1677= 4642#comment-16774642 ]=20 Wei-Chiu Chuang edited comment on HDFS-14285 at 2/22/19 1:09 AM: ----------------------------------------------------------------- Patch makes sense to me. This is exactly what hdfsPread() does. was (Author: jojochuang): Patch makes sense to me. > libhdfs hdfsRead copies entire array even if its only partially filled > ---------------------------------------------------------------------- > > Key: HDFS-14285 > URL: https://issues.apache.org/jira/browse/HDFS-14285 > Project: Hadoop HDFS > Issue Type: Bug > Components: hdfs-client, libhdfs, native > Reporter: Sahil Takiar > Assignee: Sahil Takiar > Priority: Major > Attachments: HDFS-14285.001.patch, HDFS-14285.002.patch > > > There is a bug in libhdfs {{hdfsRead}} > {code:java} > jthr =3D invokeMethod(env, &jVal, INSTANCE, jInputStream, HADOOP_ISTR= M, > "read", "([B)I", jbRarray); > if (jthr) { > destroyLocalReference(env, jbRarray); > errno =3D printExceptionAndFree(env, jthr, PRINT_EXC_ALL, > "hdfsRead: FSDataInputStream#read"); > return -1; > } > if (jVal.i < 0) { > // EOF > destroyLocalReference(env, jbRarray); > return 0; > } else if (jVal.i =3D=3D 0) { > destroyLocalReference(env, jbRarray); > errno =3D EINTR; > return -1; > } > (*env)->GetByteArrayRegion(env, jbRarray, 0, noReadBytes, buffer); > {code} > The method makes a call to {{FSInputStream#read(byte[])}}=C2=A0to fill in= the Java byte array, however, {{#read(byte[])}} is not guaranteed to fill = up the entire array, instead it returns the number of bytes=C2=A0written to= =C2=A0the array=C2=A0(which could be less than the size of the array). Yet = `{{GetByteArrayRegion}} decides to copy the entire contents of the {{jbArra= y}} into the buffer ({{noReadBytes}} is initialized to the length of the bu= ffer and is never updated). So if {{FSInputStream#read(byte[])}} decides to= read less data than the size of the byte array, the call to {{GetByteArray= Region}} will essentially copy more bytes than necessary. -- This message was sent by Atlassian JIRA (v7.6.3#76005) --------------------------------------------------------------------- To unsubscribe, e-mail: hdfs-issues-unsubscribe@hadoop.apache.org For additional commands, e-mail: hdfs-issues-help@hadoop.apache.org