zig-bitcoin / btczee

Bitcoin protocol implementation in Zig.
https://zig-bitcoin.github.io/btczee/
MIT License
48 stars 30 forks source link

Enforce payload size limit on sent message #114

Closed gdnathan closed 2 months ago

gdnathan commented 2 months ago

Following up discussion on #112 .

"To actually enforce the limit, we could do something like this maybe: src/network/wire/lib.zig

const MAX_PAYLOAD_SIZE: u32 = 32 * 1024 * 1024

const payload_len: u32 = @intCast(payload.len);
if (payload_len > MAX_PAYLOAD_SIZE) {
    return someerror
}

"

supreme2580 commented 2 months ago

@gdnathan can I be assigned to this?

onlydustapp[bot] commented 2 months ago

Hey @supreme2580! Thanks for showing interest. We've created an application for you to contribute to btczee. Go check it out on OnlyDust!

supreme2580 commented 2 months ago

@gdnathan I was reading through src/network/wire/lib.zig sendMessage function and I saw const MAX_SIZE: usize = 0x02000000; which is const MAX_PAYLOAD_SIZE: u32 = 32 * 1024 * 1024 and in sendMessage I saw

if (total_message_size > MAX_SIZE) {
        return Error.MessageTooLarge;
} 

is it not the same as limiting size on the sent message?

tdelabro commented 2 months ago

yes it is. It looks like it is missing from receiveMessage tho. You can add it there too

supreme2580 commented 2 months ago

Okay great, @tdelabro @gdnathan can I be assigned to this?

gdnathan commented 2 months ago

Hey @supreme2580 just fyi, I'm just a contributor on this project haha not a maintainer, so I cannot assign you to any tasks !