Skip to content

Commit fea0a42

Browse files
committed
Only write what was read
Without a length parameter here, we write the entire buffer, including any bogus values that come after whatever we read. This is the cause of null bytes getting into generated poms for gems.
1 parent 5f7cfcc commit fea0a42

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

ruby-tools/src/main/java/de/saumya/mojo/ruby/script/AntLauncher.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ private void writeInto(File file, OutputStream outputStream) throws IOException
147147
byte[] buffer = new byte[1024 * 4];
148148
final InputStream fileIS = new FileInputStream(file);
149149

150-
while (fileIS.read(buffer) > 0) {
151-
outputStream.write(buffer);
150+
int read = 0;
151+
while ((read = fileIS.read(buffer)) > 0) {
152+
outputStream.write(buffer, 0, read);
152153
}
153154
}
154155

0 commit comments

Comments
 (0)