NightOwl888 commented on issue #1090:
URL: https://github.com/apache/lucenenet/issues/1090#issuecomment-2573832287

   I have a theory. We added a hack to the original calculation because if the 
file size of the last buffer was 0, it would throw an 
`UnauthorizedAccessException`. We changed the offset to subtract 1 in this 
case, but there is no check to see if it went negative.
   
   
https://github.com/apache/lucenenet/blob/master/src/Lucene.Net/Store/MMapDirectory.cs#L331-L338
   
   But I am not sure the hack makes sense to begin with.
   
   The original logic was to allocate a zero byte buffer at the end:
   
   
https://github.com/apache/lucenenet/blob/master/src/Lucene.Net/Store/MMapDirectory.cs#L307-L308
   
   So, that was intended to be the case, but Microsoft doesn't allow such a 
thing. However, rather than doing whacky math with the offset, it would 
probably make more sense to skip the call to the BCL API when the last buffer 
length is 0, and instead allocate it like:
   
   ```c#
   buffers[bufNr] = ByteBuffer.Allocate(0).AsReadOnlyBuffer()
   ```
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to