Giter VIP home page Giter VIP logo

bufferio's Introduction

Image

bufferio's People

Contributors

angelobreuer avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

kmuffato

bufferio's Issues

ByteBuffer GetBuffer return a Length and offset = 0 ArraySement

Code:

            var headerBytes = Encoding.UTF8.GetBytes(Header);
            var buffer = new ByteBuffer(4 * 2 + headerBytes.Length);
            buffer.Write(ID);
            buffer.Write(headerBytes.Length);
            buffer.Write(headerBytes);
            return buffer.GetBuffer();

ByteBuffer:
Debug:

Capacity [int]:
16
Endianness [Endianness]:
BigEndian
IsEmpty [bool]:
false
IsExpandable [bool]:
true
IsExposable [bool]:
true
IsPooled [bool]:
true
IsReadOnly [bool]:
false
Length [int]:
13
Position [int]:
13

ArraySement:

Array [byte[]]:
{byte[16]}
Count [int]:
0
Offset [int]:
0

Seems Length be Capacity

ByteBuffer.cs:201
public int Remaining => Length - Position;

BigEndianReader.ReadBytes and FillReadBuffer is broken

The ReadBytes function is implemented as the following:

        public void ReadBytes(byte[] buffer, int offset, int count)
        {
            if (BaseStream.Read(buffer, offset, count) < 0)
            {
                throw new EndOfStreamException();
            }
        }

Stream.Read(buffer, offset, count) does not return a negative value. It can return less bytes than expected (if that many bytes is not available at the moment), or 0 at the end of stream. (If not at the end of stream, then the function will wait until at least one character is read. For example: if the stream is a pipe and no bytes are available, then reading will hang until the writer either closes the stream, or writes at least one byte.) So the result is that the function may silently fill the array with less bytes than expected, and give no indication that this is what has happened.

In addition, the non-public FillReadBuffer function is implemented incorrectly. Again, Stream.Read may return less bytes than expected; this is normal and doesn't necessarily mean that the end of stream has been reached.

Contrast this - e.g. using ILSpy utility - with the implementation of .NET BinaryReader, where ReadBytes returns the array instead of filling it, and both ReadBytes and the typed Read functions (using non-public function FillBuffer) repeatedly call Stream.Read if necessary.

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.