8000 Fix Buffer Handling Vulnerabilities in write Method by simei2k · Pull Request #547 · chatty/chatty · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix Buffer Handling Vulnerabilities in write Method #547

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/com/pngencoder/PngEncoderIdatChunksOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,30 @@ public void write(byte[] b) throws IOException {

@Override
public void write(byte[] b, in 90B9 t off, int len) throws IOException {
// Check for null input
if (b == null) {
throw new NullPointerException("Input byte array cannot be null");
}

// Check array bounds
if (off < 0 || len < 0 || off + len > b.length) {
throw new ArrayIndexOutOfBoundsException("Invalid offset or length parameters");
}

// Handle buffer management
if (len >= buf.length) {
flushBuffer();
writeIdatChunk(b, off, len);
return;
}

if (len > buf.length - count) {
flushBuffer();
}

System.arraycopy(b, off, buf, count, len);
count += len;
}

@Override
public void flush() throws IOException {
flushBuffer();
super.flush();
}

private void flushBuffer() throws IOException {
if (count > 0) {
writeIdatChunk(buf, 0, count);
Expand Down
0