Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insufficient Characters Read #266

Closed
j4587698 opened this issue May 17, 2024 · 6 comments
Closed

Insufficient Characters Read #266

j4587698 opened this issue May 17, 2024 · 6 comments

Comments

@j4587698
Copy link
Contributor

The problem

When the stream read speed is not very fast (such as reading from a network data stream), there may be an issue of incomplete reads if the byte read length is too long. During testing, when retrieving built-in images, a significant number of images were only partially read. Upon inspecting the source code, it was discovered that the program's reading process does not handle read lengths, and the code directly assumes a completed read with lines like source.Read(buffer, 0, buffer.Length);. When the stream is slow, this may result in only a portion of the content being read, leading to problems.

Environment

  • ATL version (or git revision) that exhibits the issue:latest
  • Last ATL version that did not exhibit the issue (if applicable):none
  • OS/version used to run ATL:all

Details

37468c59-bf83-4042-86e7-0fed580b6d67

Code To Reproduce Issue [ Good To Have ]

Please remember that with sample code it's easier to reproduce the bug and it's much faster to fix it.

@Zeugma440
Copy link
Owner

I've changed the way pictures are read to rely on a read buffer instead of trying to read everything in one go.

You can control its size using ATL.Settings.FileBufferSize.

Can you test using the source code or do you need a release?

@j4587698
Copy link
Contributor Author

I apologize for not noticing your reply earlier.
I have now addressed the issue by using an intermediary stream.
I think you can go ahead and release it directly.

@Zeugma440
Copy link
Owner

Fix is available in today's v5.24. Please close the issue if it works on your side.

@j4587698
Copy link
Contributor Author

There still seems to be a problem with the test. Looking at the code, for instance around line 1079 in ID3v2.cs, it appears that byte.Read is still being used.

int picSize = dataSize - (int)(source.Position - position);

byte[] data;
if (tag.UsesUnsynchronisation)
{
    data = decodeUnsynchronizedStream(source, picSize);
}
else
{
    data = new byte[picSize];
    source.Read(data, 0, picSize);
}
PictureInfo picInfo = PictureInfo.fromBinaryData(data, picType, getImplementedTagType(), picCode, picturePosition);
picInfo.Description = description;

@Zeugma440
Copy link
Owner

There still seems to be a problem with the test. Looking at the code, for instance around line 1079 in ID3v2.cs, it appears that byte.Read is still being used.

Sorry, I forgot about that one. Thanks for letting me know. The fix will be available in the next release 😅

@Zeugma440
Copy link
Owner

Fix is available in today's v5.25. Please close the issue if it works on your side.

@j4587698 j4587698 closed this as completed Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants