fix: limut stdout record to 2048bytes to prevent header length overflow
Some checks failed
gitea-sync/luafcgi/pipeline/head There was a failure building this commit

This commit is contained in:
DanyLE 2023-02-01 16:41:09 +01:00
parent 2cda1b84c0
commit 3ac6971a36
2 changed files with 14 additions and 3 deletions

View File

@ -17,7 +17,7 @@ rand = "0.8.5"
twoway = "0.2.2"
[profile.release]
opt-level = 's'
opt-level = 3
# 's' for size
lto = true
# panic = 'abort'

View File

@ -4,7 +4,7 @@ use rand::Rng;
use std::collections::HashMap;
use std::ffi::CString;
use std::fmt::Arguments;
use std::io::{BufRead, BufReader, Error, ErrorKind, Read, Write};
use std::io::{BufRead, BufReader, Cursor, Error, ErrorKind, Read, Write};
use std::os::fd::RawFd;
use std::os::unix::io::AsRawFd;
use std::time::SystemTime;
@ -724,7 +724,18 @@ impl FCGIOStream {
}
fn write_record(&mut self, buf: Vec<u8>) -> Result<(), std::io::Error> {
fcgi_send_stdout(self, self.id, Some(buf))?;
let mut buf_reader = BufReader::with_capacity(2048, Cursor::new(buf));
loop {
let length = {
let buffer = buf_reader.fill_buf()?;
fcgi_send_stdout(self, self.id, Some(buffer.to_vec()))?;
buffer.len()
};
if length == 0 {
break;
}
buf_reader.consume(length);
}
Ok(())
}
}