Skip to content

Commit 2993593

Browse files
committed
Fix stall at startup issue
1 parent 285fa8c commit 2993593

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

java/src/main/java/com/github/jtraglia/dff/Client.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,12 @@ public void connect() throws IOException {
8282

8383
// Read method name (up to 64 bytes)
8484
ByteBuffer methodBuffer = ByteBuffer.allocate(MAX_METHOD_LENGTH);
85-
int methodLength = channel.read(methodBuffer);
86-
if (methodLength <= 0) {
87-
throw new IOException("Failed to read method name");
88-
}
85+
// Read method name (exactly 64 bytes, null-padded by server)
86+
readFullyBlocking(methodBuffer);
87+
methodBuffer.flip();
8988
// Find null terminator or use full length
90-
int actualLength = methodLength;
91-
for (int i = 0; i < methodLength; i++) {
89+
int actualLength = MAX_METHOD_LENGTH;
90+
for (int i = 0; i < MAX_METHOD_LENGTH; i++) {
9291
if (methodBuffer.get(i) == 0) {
9392
actualLength = i;
9493
break;

python/dff/server.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,12 @@ def _handle_client(self, conn: socket.socket, addr: str) -> None:
122122
# Send output shared memory ID
123123
conn.sendall(struct.pack(">I", output_shm.shmid))
124124

125-
# Send method name
126-
conn.sendall(self.method.encode())
125+
# Send method name (fixed 64 bytes, null-padded)
126+
method_padded = self.method.encode().ljust(64, b'\x00')
127+
conn.sendall(method_padded)
128+
129+
# Set timeout for main loop communication
130+
conn.settimeout(60.0)
127131

128132
# Store client
129133
with self.clients_lock:

rust/src/client.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,13 @@ impl Client {
9696
}
9797
self.output_shm = Some(output_shm_ptr as *mut u8);
9898

99-
// Read method name (up to 64 bytes)
99+
// Read method name (exactly 64 bytes, null-padded by server)
100100
let mut method_bytes = [0u8; 64];
101-
let method_length = stream.read(&mut method_bytes).await?;
102-
self.method = String::from_utf8_lossy(&method_bytes[..method_length]).to_string();
101+
stream.read_exact(&mut method_bytes).await?;
102+
let method_end = method_bytes.iter().position(|&b| b == 0).unwrap_or(64);
103+
self.method = String::from_utf8_lossy(&method_bytes[..method_end]).to_string();
103104

104-
log::info!("Connected with fuzzing method: {}", self.method);
105+
println!("Connected with fuzzing method: {}", self.method);
105106

106107
self.conn = Some(stream);
107108
Ok(())

0 commit comments

Comments
 (0)