Segmentation fault
themihai opened this issue · 3 comments
themihai commented
Watching and shuffling through a video file produces a segmentation fault.
Initial command btfs -d torrents/av.torrent mnt2
handle_piece_finished_alert: 1398
handle_piece_finished_alert: 1403
handle_piece_finished_alert: 1401
handle_piece_finished_alert: 1404
handle_piece_finished_alert: 1389
unique: 8, opcode: READ (15), nodeid: 4, insize: 80, pid: 5015
read[0] 65536 bytes from 338395136 flags: 0x0
handle_read_piece_alert: piece 1290 size 0
Segmentation fault: 11
OSX Sierra
btfs --version
btfs version: 2.15
libtorrent version: 1.1.4.0
OSXFUSE 3.6.3
FUSE library version: 2.9.7
fuse: no mount point
johang commented
Piece size is 0. Maybe the read request failed.
I can't reproduce this. Can you try with this patch?
diff --git a/src/btfs.cc b/src/btfs.cc
index 2a74bac..f4b3f2c 100644
--- a/src/btfs.cc
+++ b/src/btfs.cc
@@ -140,6 +140,13 @@ Read::Read(char *buf, int index, off_t offset, size_t size) {
}
}
+void Read::fail(int piece) {
+ for (parts_iter i = parts.begin(); i != parts.end(); ++i) {
+ if (i->part.piece == piece && !i->filled)
+ failed = true;
+ }
+}
+
void Read::copy(int piece, char *buffer, int size) {
for (parts_iter i = parts.begin(); i != parts.end(); ++i) {
if (i->part.piece == piece && !i->filled)
@@ -184,11 +191,14 @@ int Read::read() {
// Move sliding window to first piece to serve this request
jump(parts.front().part.piece, size());
- while (!finished())
+ while (!finished() && !failed)
// Wait for any piece to downloaded
pthread_cond_wait(&signal_cond, &lock);
- return size();
+ if (failed)
+ return -EIO;
+ else
+ return size();
}
static void
@@ -240,12 +250,19 @@ setup() {
static void
handle_read_piece_alert(libtorrent::read_piece_alert *a, Log *log) {
- printf("%s: piece %d size %d\n", __func__, a->piece, a->size);
+ printf("%s: piece %d size %d buf %p\n", __func__, a->piece, a->size,
+ a->buffer.get());
pthread_mutex_lock(&lock);
- for (reads_iter i = reads.begin(); i != reads.end(); ++i) {
- (*i)->copy(a->piece, a->buffer.get(), a->size);
+ if (a->ec) {
+ for (reads_iter i = reads.begin(); i != reads.end(); ++i) {
+ (*i)->fail(a->piece);
+ }
+ } else {
+ for (reads_iter i = reads.begin(); i != reads.end(); ++i) {
+ (*i)->copy(a->piece, a->buffer.get(), a->size);
+ }
}
pthread_mutex_unlock(&lock);
@@ -511,6 +528,9 @@ btfs_read(const char *path, char *buf, size_t size, off_t offset,
// Wait for read to finish
int s = r->read();
+ if (s < 0)
+ printf("btfs_read about to return -1");
+
reads.remove(r);
delete r;
diff --git a/src/btfs.h b/src/btfs.h
index 020881b..c1cd290 100644
--- a/src/btfs.h
+++ b/src/btfs.h
@@ -60,6 +60,8 @@ class Read
public:
Read(char *buf, int index, off_t offset, size_t size);
+ void fail(int piece);
+
void copy(int piece, char *buffer, int size);
void trigger();
@@ -71,6 +73,8 @@ public:
int read();
private:
+ bool failed = false;
+
std::vector<Part> parts;
};
themihai commented
Thanks for the patch! I will update when/if I reproduce it. It happened to me twice(before I reported it) stressing the Chrome player (-> File -> Open File) .
johang commented
Did you reproduce it?