libpnet / libpnet/libpnet

'arithmetic operation overflowed' when not calling set_header_length

Open
#200 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.6k
Forks
329
PR merge metrics
No merged PRs in 30d

Description

The following code sample will panic with an 'arithmetic operation overflowed' error if set_header_length is not called or if the value is set to 16 or greater

let mut bytes = [0u8; 100];
let mut ethernet : MutableEthernetPacket = ethernet::MutableEthernetPacket::new(&mut bytes).unwrap();
ethernet.set_source(mac);
ethernet.set_destination(mac);

{
    let mut ipv4 = pnet::packet::ipv4::MutableIpv4Packet::new(ethernet.payload_mut()).unwrap();

    ipv4.set_source(source_ip);
    ipv4.set_destination(destination_ip);
    //ipv4.set_header_length(8);
    ipv4.set_dscp(0);

    {
        let mut echo = echo_request::MutableEchoRequestPacket::new(ipv4.payload_mut()).unwrap();

        echo.set_icmp_type(icmp::icmp_types::EchoRequest);
        echo.set_icmp_code(echo_request::icmp_codes::NoCode);
        echo.set_identifier(1);
        echo.set_sequence_number(1);

    }


}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied Rust reproduction and inspect the IPv4 mutable packet handling around header length and payload creation. Reproduce the panic both without set_header_length and with values of 16 or greater; done means the example no longer panics in those cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.