summaryrefslogtreecommitdiff
path: root/libs/samba/src/main/cpp
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2024-08-25 00:09:26 +0200
committerJoel Klinghed <the_jk@spawned.biz>2024-08-25 00:09:26 +0200
commitcd0f76a239d13713f6695e952c3eb68ec1014c66 (patch)
tree2b37ae2e3f75c396f9b369fe3afc6e25af9409b8 /libs/samba/src/main/cpp
parent416efab10af847525186f936d98303735fa477ec (diff)
samba: Fix reading/writing large amounts of data
Two bugs: * Didn't consider smb2_context max read/write size. * total was not increased when max was hit
Diffstat (limited to 'libs/samba/src/main/cpp')
-rw-r--r--libs/samba/src/main/cpp/samba.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/libs/samba/src/main/cpp/samba.cpp b/libs/samba/src/main/cpp/samba.cpp
index 4a8af51..302fb3a 100644
--- a/libs/samba/src/main/cpp/samba.cpp
+++ b/libs/samba/src/main/cpp/samba.cpp
@@ -63,13 +63,15 @@ class File {
int32_t read(uint8_t* data, int32_t size) {
if (size <= 0) return 0;
+ const uint32_t max = std::min(smb2_get_max_read_size(context_.get()),
+ static_cast<uint32_t>(std::numeric_limits<int>::max()));
int32_t total = 0;
- while (size > std::numeric_limits<int>::max()) {
- int ret = smb2_read(context_.get(), fh_, data,
- std::numeric_limits<int>::max());
+ while (size > max) {
+ int ret = smb2_read(context_.get(), fh_, data, max);
if (ret < 0) return total ? total : ret;
- if (ret != std::numeric_limits<int>::max())
- return total + ret;
+ total += ret;
+ if (ret != max)
+ return total;
data += ret;
size -= ret;
}
@@ -80,13 +82,15 @@ class File {
int32_t write(const uint8_t* data, int32_t size) {
if (size <= 0) return 0;
+ const uint32_t max = std::min(smb2_get_max_write_size(context_.get()),
+ static_cast<uint32_t>(std::numeric_limits<int>::max()));
int32_t total = 0;
- while (size > std::numeric_limits<int>::max()) {
- int ret = smb2_write(context_.get(), fh_, data,
- std::numeric_limits<int>::max());
+ while (size > max) {
+ int ret = smb2_write(context_.get(), fh_, data, max);
if (ret < 0) return total ? total : ret;
- if (ret != std::numeric_limits<int>::max())
- return total + ret;
+ total += ret;
+ if (ret != max)
+ return total;
data += ret;
size -= ret;
}