From a9b9631c5cfa5cdbdbc4d5d0a5a1bba0efff0b64 Mon Sep 17 00:00:00 2001 From: Takeshi Nakatani Date: Sat, 11 Oct 2025 05:23:59 +0000 Subject: [PATCH] Fixed to not call xmlReadMemory if data length is 0 --- src/s3fs.cpp | 10 ++++++++++ src/s3fs_xml.cpp | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/s3fs.cpp b/src/s3fs.cpp index c90c2c9..65507c9 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -3586,6 +3586,16 @@ static int list_bucket(const char* path, S3ObjList& head, const char* delimiter, // std::string encbody = get_encoded_cr_code(responseBody.c_str()); + // [NOTE] + // If encbody is empty, xmlReadMemory will output the message + // ":1: parser error : Document is empty" to stderr. + // Make sure encbody is not empty beforehand. + // + if(encbody.empty()){ + S3FS_PRN_ERR("The data length passed to xmlReadMemory is 0."); + return -EIO; + } + // xmlDocPtr std::unique_ptr doc(xmlReadMemory(encbody.c_str(), static_cast(encbody.size()), "", nullptr, 0), xmlFreeDoc); if(nullptr == doc){ diff --git a/src/s3fs_xml.cpp b/src/s3fs_xml.cpp index c1fb55a..6548f56 100644 --- a/src/s3fs_xml.cpp +++ b/src/s3fs_xml.cpp @@ -451,11 +451,16 @@ bool simple_parse_xml(const char* data, size_t len, const char* key, std::string { bool result = false; - if(!data || !key){ + if(!data || !key || 0 == len){ return false; } value.clear(); + // [NOTE] + // If data is not nullptr and len is 0, this function will output the message + // ":1: parser error : Document is empty" to stderr. + // Make sure len is not 0 beforehand. + // std::unique_ptr doc(xmlReadMemory(data, static_cast(len), "", nullptr, 0), xmlFreeDoc); if(nullptr == doc){ return false;