mirror of
https://github.com/fail0verflow/switch-coreboot.git
synced 2025-05-04 01:39:18 -04:00
This very short patch fixes nrv2b compression in lar.
It also fixes lzma compression in lar to fix the silent memory corruption that was possible when files didn't compress well. It adds some comments to both files and the file that calls them. Signed-off-by: Myles Watson <mylesgw@gmail.com> Acked-by: Stefan Reinauer <stepan@coresystems.de> git-svn-id: svn://coreboot.org/repository/coreboot-v3@658 f3766cd6-281f-0410-b1cd-43a5c92072e9
This commit is contained in:
parent
7920e8a96a
commit
c4a9590044
3 changed files with 31 additions and 4 deletions
|
@ -846,7 +846,7 @@ int maxsize(struct lar *lar, char *name)
|
|||
|
||||
/**
|
||||
* Compress an area according to an algorithm. If the area grows,
|
||||
* use no compression.
|
||||
* use no compression. The size of temp should be at least size bytes.
|
||||
* @param ptr data to be compressed
|
||||
* @param size size of the data
|
||||
* @param temp destination of compressed data
|
||||
|
|
|
@ -283,11 +283,21 @@ int main(int argc, char *argv[])
|
|||
#else
|
||||
extern "C" {
|
||||
|
||||
/**
|
||||
* Compress a buffer with lzma
|
||||
* Don't copy the result back if it is too large.
|
||||
* @param in a pointer to the buffer
|
||||
* @param in_len the length in bytes
|
||||
* @param out a pointer to a buffer of at least size in_len
|
||||
* @param out_len a pointer to the compressed length of in
|
||||
*/
|
||||
|
||||
void do_lzma_compress(char *in, int in_len, char *out, int *out_len) {
|
||||
std::vector<unsigned char> result;
|
||||
result = LZMACompress(std::vector<unsigned char>(in, in + in_len));
|
||||
*out_len = result.size();
|
||||
std::memcpy(out, &result[0], *out_len);
|
||||
if (*out_len < in_len)
|
||||
std::memcpy(out, &result[0], *out_len);
|
||||
}
|
||||
|
||||
void do_lzma_uncompress(char *dst, int dst_len, char *src, int src_len) {
|
||||
|
|
|
@ -1304,11 +1304,28 @@ void Encode(void) /* compression */
|
|||
#endif
|
||||
|
||||
#ifdef COMPACT
|
||||
|
||||
/**
|
||||
* Compress a buffer with nrv2b
|
||||
* Don't copy the result back if it is too large
|
||||
* @param in a pointer to the buffer
|
||||
* @param in_len the length in bytes
|
||||
* @param out a pointer to a buffer of at least size in_len
|
||||
* @param out_len a pointer to the compressed length of in
|
||||
*/
|
||||
|
||||
void do_nrv2b_compress(uint8_t *in, int in_len, uint8_t *out, int *out_len) {
|
||||
unsigned long new_out_len = in_len + (in_len/8) + 256;
|
||||
out = malloc(new_out_len);
|
||||
ucl_nrv2b_99_compress(in, in_len, out, &new_out_len, 0 );
|
||||
uint8_t *new_out = malloc(new_out_len);
|
||||
if (new_out == NULL) {
|
||||
printf("Not enough memory to allocate buffer.\n");
|
||||
exit(1);
|
||||
}
|
||||
ucl_nrv2b_99_compress(in, in_len, new_out, &new_out_len, 0 );
|
||||
*out_len = (int) new_out_len;
|
||||
if (*out_len < in_len)
|
||||
memcpy(out, new_out, *out_len);
|
||||
free(new_out);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue