IndySockets / Indy

Indy - Internet Direct
https://www.indyproject.org
451 stars 153 forks source link

Wont Reset Bytes - A Bug? #526

Closed caryyu closed 7 months ago

caryyu commented 7 months ago

https://github.com/IndySockets/Indy/blob/40ba7a2b08bb05a2269dd52f281a3dd9349a4974/Lib/Core/IdBuffer.pas#L619

rlebeau commented 7 months ago

I don't understand what you are trying to describe. That line is in CompactHead(), which simply removes bytes from the front of the buffer at indexes 0..FHeadIndex-1. The remaining bytes from index FHeadIndex onward are copied to the front of the buffer. Any bytes at the end of the buffer are simply ignored as they don't fall within the current buffer Size, which doesn't change while compacting the buffer. So, there is nothing to reset.

caryyu commented 7 months ago

This isn't the real removal as the info still is held in the memory, when people use Extract* series methods, some of the old bytes could also be extracted from. and also, the overridden ones could lead to the data inconsistent.

rlebeau commented 7 months ago

This isn't the real removal as the info still is held in the memory, when people use Extract* series methods, some of the old bytes could also be extracted from.

The Extract*() methods merely increment the FHeadIndex, the bytes aren't physically removed from the buffer until it is compacted. So yes, in theory, "old" bytes could still be extracted again, if one really wanted to do so. But why?

You pointed out a line of code in the compact method, and said it needs to reset something, but there is nothing to reset.

and also, the overridden ones could lead to the data inconsistent.

I don't understand what you are referring to. What "overridden ones"? Overwritten bytes?

Again, can you please clarify the actual problem with a real-world example?

caryyu commented 7 months ago

Closed as I chose another path.