diff --git a/td/telegram/files/PartsManager.cpp b/td/telegram/files/PartsManager.cpp index ed1d8ec32..1513e78ba 100644 --- a/td/telegram/files/PartsManager.cpp +++ b/td/telegram/files/PartsManager.cpp @@ -35,13 +35,14 @@ void PartsManager::set_streaming_offset(int64 offset) { }; if (offset < 0 || need_check_ || (!unknown_size_flag_ && get_size() < offset)) { streaming_offset_ = 0; + LOG(ERROR) << "Ignore streaming_offset (1)"; return; } auto part_i = offset / part_size_; - if (part_i >= MAX_PART_COUNT) { + if (use_part_count_limit_ && part_i >= MAX_PART_COUNT) { streaming_offset_ = 0; - // error? + LOG(ERROR) << "Ignore streaming_offset (2)"; return; } diff --git a/td/telegram/files/ResourceState.h b/td/telegram/files/ResourceState.h index e0abf7285..47943e674 100644 --- a/td/telegram/files/ResourceState.h +++ b/td/telegram/files/ResourceState.h @@ -30,7 +30,10 @@ class ResourceState { } bool update_estimated_limit(int64 extra) { - auto new_estimated_limit = used_ + extra; + // unused() must be positive, i.e. used_ + using_ must be less than limit_ + // TODO: use exact intersection between using_ and extra. + auto using_and_extra_intersection = min(using_, extra); // between 0 and min(using_, extra) + auto new_estimated_limit = used_ + using_ + extra - using_and_extra_intersection; // Use extra extra limit if (new_estimated_limit < limit_) {