mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-06-09 23:36:03 +09:00
lzo: add a function to check the validity of the header
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com> Reviewed-by: Tom Rini <trini@konsulko.com> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
02035d0086
commit
d753f942ec
|
@ -31,6 +31,9 @@ int lzo1x_decompress_safe(const unsigned char *src, size_t src_len,
|
||||||
int lzop_decompress(const unsigned char *src, size_t src_len,
|
int lzop_decompress(const unsigned char *src, size_t src_len,
|
||||||
unsigned char *dst, size_t *dst_len);
|
unsigned char *dst, size_t *dst_len);
|
||||||
|
|
||||||
|
/* check if the header is valid (based on magic numbers) */
|
||||||
|
bool lzop_is_valid_header(const unsigned char *src);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return values (< 0 = Error)
|
* Return values (< 0 = Error)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -30,16 +30,29 @@ static const unsigned char lzop_magic[] = {
|
||||||
|
|
||||||
#define HEADER_HAS_FILTER 0x00000800L
|
#define HEADER_HAS_FILTER 0x00000800L
|
||||||
|
|
||||||
|
|
||||||
|
bool lzop_is_valid_header(const unsigned char *src)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
/* read magic: 9 first bytes */
|
||||||
|
for (i = 0; i < ARRAY_SIZE(lzop_magic); i++) {
|
||||||
|
if (*src++ != lzop_magic[i])
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static inline const unsigned char *parse_header(const unsigned char *src)
|
static inline const unsigned char *parse_header(const unsigned char *src)
|
||||||
{
|
{
|
||||||
u16 version;
|
u16 version;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* read magic: 9 first bytes */
|
if (!lzop_is_valid_header(src))
|
||||||
for (i = 0; i < ARRAY_SIZE(lzop_magic); i++) {
|
return NULL;
|
||||||
if (*src++ != lzop_magic[i])
|
|
||||||
return NULL;
|
/* skip header */
|
||||||
}
|
src += 9;
|
||||||
|
|
||||||
/* get version (2bytes), skip library version (2),
|
/* get version (2bytes), skip library version (2),
|
||||||
* 'need to be extracted' version (2) and
|
* 'need to be extracted' version (2) and
|
||||||
* method (1) */
|
* method (1) */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user