[Storage] desktop ListenerInternal never initializes rest_operation_

Đang mở Phù hợp với người mới
#1,966 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
88/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp
Lĩnh vực
backend

Hướng nghiên cứu

Trong storage/src/desktop/listener_desktop.cc, hàm khởi tạo khởi tạo listener_, bytes_transferred_ và total_byte_count_; issue cho biết rest_operation_ không có giá trị khởi tạo trong header. Đọc phần khai báo và hàm khởi tạo của ListenerInternal, sau đó kiểm tra hành vi của hàm hủy đối với listener được dùng khi PutFile thất bại trước khi tạo RestOperation. Hoàn tất khi trường hợp đó không còn truy cập con trỏ chưa được khởi tạo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

storage/src/desktop/listener_desktop.cc:

ListenerInternal::ListenerInternal(Listener *listener)
    : listener_(listener), bytes_transferred_(-1), total_byte_count_(-1) {}

ListenerInternal::~ListenerInternal() {
  MutexLock lock(mutex_);
  if (rest_operation_) {
    rest_operation_->cleanup().UnregisterObject(this);
    rest_operation_->set_listener(nullptr);
  }
}

rest_operation_ has no initializer in the header either. It only gets set in set_rest_operation(), which runs when a RestOperation is created.

So a Listener passed to a call that never creates one gets destroyed with garbage in it. PutFile() on a path that can't be opened does this. PutFileInternal completes with "Could not read file." and returns before RestCall.

class L : public firebase::storage::Listener {
  void OnPaused(firebase::storage::Controller*) override {}
  void OnProgress(firebase::storage::Controller*) override {}
};

auto* l = new L();
auto f = ref.PutFile("/no/such/file", l);
// wait for f, it fails with kErrorUnknown
delete l;
  • Windows x64, MSVC release: access violation in the destructor
  • Linux and macOS: passes, the allocation happened to be zeroed

13.12.0, and main is the same.

Fix is rest_operation_(nullptr) in the constructor.

Ngôn ngữ chính
C++
Star
326
Fork
137
Merge trung bình
3 ngày 8 giờ
Pull request đã merge (30 ngày)
17

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của firebase/firebase-cpp-sdk

Tất cả issue của firebase/firebase-cpp-sdk

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.