Coder Social home page Coder Social logo

Comments (3)

hug-dev avatar hug-dev commented on August 16, 2024

It was decided that, for now, the size field given in the header should match the size of the header in the 1.0 wire protocol format, as a measure of safety.
If the magic number given is correct, we should however always read the number of bytes given in the header for the rest of the request header and then check if that number is correct. If it is correct, we can then deserialize the header.
It is the following change:

diff --git a/src/requests/request/request_header.rs b/src/requests/request/request_header.rs
index 2829679..c41f527 100644
--- a/src/requests/request/request_header.rs
+++ b/src/requests/request/request_header.rs
@@ -91,11 +91,16 @@ impl RawRequestHeader {
     pub fn read_from_stream<R: Read>(mut stream: &mut R) -> Result<RawRequestHeader> {
         let magic_number = get_from_stream!(stream, u32);
         let hdr_size = get_from_stream!(stream, u16);
-        if magic_number != MAGIC_NUMBER || hdr_size != REQUEST_HDR_SIZE {
+        if magic_number != MAGIC_NUMBER {
+            error!("The magic number ({}) in the request is incorrect.", magic_number);
             return Err(ResponseStatus::InvalidHeader);
         }
         let mut bytes = vec![0_u8; usize::try_from(hdr_size)?];
         stream.read_exact(&mut bytes)?;
+        if hdr_size != REQUEST_HDR_SIZE {
+            error!("The header size ({}) in the request is incorrect.", hdr_size);
+            return Err(ResponseStatus::InvalidHeader);
+        }

         let raw_request: RawRequestHeader = bincode::deserialize(&bytes)?;
         if raw_request.version_maj != 1 || raw_request.version_min != 0 {

from parsec.

hug-dev avatar hug-dev commented on August 16, 2024

And similar changes for the responses!

from parsec.

hug-dev avatar hug-dev commented on August 16, 2024

Fixed as per linked PR.

from parsec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.