1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-22 12:22:06 +01:00

Fix OOM when detached signing large files

Fixes #432
This commit is contained in:
Paul Schaub 2024-03-17 17:11:28 +01:00
parent a9cec16dc6
commit 265f72d99f
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 19 additions and 3 deletions

View file

@ -4,7 +4,6 @@
package org.pgpainless.sop; package org.pgpainless.sop;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
@ -98,10 +97,10 @@ public class DetachedSignImpl implements DetachedSign {
} }
} }
ByteArrayOutputStream buffer = new ByteArrayOutputStream(); OutputStream sink = new NullOutputStream();
try { try {
EncryptionStream signingStream = PGPainless.encryptAndOrSign() EncryptionStream signingStream = PGPainless.encryptAndOrSign()
.onOutputStream(buffer) .onOutputStream(sink)
.withOptions(ProducerOptions.sign(signingOptions) .withOptions(ProducerOptions.sign(signingOptions)
.setAsciiArmor(armor)); .setAsciiArmor(armor));

View file

@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2024 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.sop;
import java.io.OutputStream;
/**
* {@link OutputStream} that simply discards bytes written to it.
*/
public class NullOutputStream extends OutputStream {
@Override
public void write(int b) {
// NOP
}
}