Giter Club home page Giter Club logo

Comments (3)

Pastequee avatar Pastequee commented on September 2, 2024 1

@ColinFinck Hey, thanks for all the explanations, make sense now. And ye this fixes all the new issues I had so you can make a minor bug fix with the changes.
I am fuzzing the latest version and it looks very promising ! No crashes nor infinite loops so far. I am gonna let it run for a while to see if it can found deeper bug but so far so good, I'll get back to you if I find something

from ntfs.

ColinFinck avatar ColinFinck commented on September 2, 2024

The fix 441ea7b for #24 introduced a new bug because sector_position_end still needs to be verified inside the loop because it is incremented at each iteration and so still needs to be checked.

sector_position begins at NTFS_BLOCK_SIZE - mem::size_of::<u16>().
sector_position_end begins at sector_position + mem::size_of::<u16>(), hence it effectively begins at NTFS_BLOCK_SIZE.

Both variables are incremented by NTFS_BLOCK_SIZE in each iteration.

The loop runs while array_position < array_end.
array_position begins at update_sequence_array_start(), which equals update_sequence_offset() + mem::size_of::<u16>().
array_end is set to update_sequence_offset() + update_sequence_size(), which equals update_sequence_offset() + update_sequence_count * mem::size_of::<u16>().
I'm incrementing array_position by mem::size_of::<u16>() in every iteration.

So to determine the number of iterations, we can calculate:

NumberOfIterations = (array_end - array_position) / mem::size_of::<u16>()
                   = (update_sequence_offset() + update_sequence_count * mem::size_of::<u16>() - update_sequence_offset() - mem::size_of::<u16>()) / mem::size_of::<u16>()
                   = (update_sequence_count * mem::size_of::<u16>() - mem::size_of::<u16>()) / mem::size_of::<u16>()
                   = update_sequence_count - 1

As a result, we know that sector_position_end will be set to (update_sequence_count - 1) * NTFS_BLOCK_SIZE at the end of the loop.
update_sequence_count - 1 is actually what I wanted to calculate in update_sequence_array_count().
Unfortunately, this also proves that I indeed messed up, because I'm subtracting mem::size_of::<u16>() there instead of just 1.
However, this calculation also shows that I can safely determine the final value of sector_position_end beforehand, which is what I'm doing with the newly introduced sectors_end variable in 441ea7b.

All of this can likely be simplified. But it's not necessary to check sector_position_end in every iteration when we know the final value beforehand and can just check that once.

from ntfs.

ColinFinck avatar ColinFinck commented on September 2, 2024

Fixed this and #26 in 5cc2416
Please let me know if that fixes the particular crash you were hitting, then I will publish a bugfix release 0.3.1

from ntfs.

Related Issues (19)

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.