You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by we...@apache.org on 2019/02/23 01:54:54 UTC
[hadoop] branch trunk updated: HDFS-14285. libhdfs hdfsRead copies
entire array even if its only partially filled. Contributed by Sahil
Takiar.
This is an automated email from the ASF dual-hosted git repository.
weichiu pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push:
new f19c844 HDFS-14285. libhdfs hdfsRead copies entire array even if its only partially filled. Contributed by Sahil Takiar.
f19c844 is described below
commit f19c844e7515c00b5a11e4fd971e45d98629b1a6
Author: Sahil Takiar <st...@apache.org>
AuthorDate: Fri Feb 22 17:53:50 2019 -0800
HDFS-14285. libhdfs hdfsRead copies entire array even if its only partially filled. Contributed by Sahil Takiar.
Signed-off-by: Wei-Chiu Chuang <we...@apache.org>
---
.../hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c
index 55fef24..9c2ee8c 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c
@@ -1396,7 +1396,6 @@ tSize hdfsRead(hdfsFS fs, hdfsFile f, void* buffer, tSize length)
{
jobject jInputStream;
jbyteArray jbRarray;
- jint noReadBytes = length;
jvalue jVal;
jthrowable jthr;
JNIEnv* env;
@@ -1452,7 +1451,12 @@ tSize hdfsRead(hdfsFS fs, hdfsFile f, void* buffer, tSize length)
errno = EINTR;
return -1;
}
- (*env)->GetByteArrayRegion(env, jbRarray, 0, noReadBytes, buffer);
+ // We only copy the portion of the jbRarray that was actually filled by
+ // the call to FsDataInputStream#read; #read is not guaranteed to fill the
+ // entire buffer, instead it returns the number of bytes read into the
+ // buffer; we use the return value as the input in GetByteArrayRegion to
+ // ensure don't copy more bytes than necessary
+ (*env)->GetByteArrayRegion(env, jbRarray, 0, jVal.i, buffer);
destroyLocalReference(env, jbRarray);
if ((*env)->ExceptionCheck(env)) {
errno = printPendingExceptionAndFree(env, PRINT_EXC_ALL,
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org