summaryrefslogtreecommitdiffstats
path: root/src/image/zlib.c
diff options
context:
space:
mode:
authorMichael Brown2025-04-22 13:13:22 +0200
committerMichael Brown2025-04-22 13:32:12 +0200
commitc059b341707863f8ecc4ecde75dd608dda72fdad (patch)
treea3d99be7a70692ba478268018db620a3de2b1c28 /src/image/zlib.c
parent[image] Remove userptr_t from image definition (diff)
downloadipxe-c059b341707863f8ecc4ecde75dd608dda72fdad.tar.gz
ipxe-c059b341707863f8ecc4ecde75dd608dda72fdad.tar.xz
ipxe-c059b341707863f8ecc4ecde75dd608dda72fdad.zip
[deflate] Remove userptr_t from decompression code
Simplify the deflate, zlib, and gzip decompression code by assuming that all content is fully accessible via pointer dereferences. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/image/zlib.c')
-rw-r--r--src/image/zlib.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/image/zlib.c b/src/image/zlib.c
index a42c47e1b..d7deee88b 100644
--- a/src/image/zlib.c
+++ b/src/image/zlib.c
@@ -27,7 +27,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <errno.h>
#include <assert.h>
#include <ipxe/deflate.h>
-#include <ipxe/uaccess.h>
#include <ipxe/image.h>
#include <ipxe/zlib.h>
@@ -41,11 +40,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
* Extract compressed data to image
*
* @v format Compression format code
- * @v in Compressed input chunk
+ * @v data Compressed input data
+ * @v len Length of compressed input data
* @v extracted Extracted image
* @ret rc Return status code
*/
-int zlib_deflate ( enum deflate_format format, struct deflate_chunk *in,
+int zlib_deflate ( enum deflate_format format, const void *data, size_t len,
struct image *extracted ) {
struct deflate *deflate;
struct deflate_chunk out;
@@ -64,14 +64,12 @@ int zlib_deflate ( enum deflate_format format, struct deflate_chunk *in,
/* (Re)initialise decompressor */
deflate_init ( deflate, format );
- /* (Re)initialise input chunk */
- in->offset = 0;
-
/* Initialise output chunk */
deflate_chunk_init ( &out, extracted->data, 0, extracted->len );
/* Decompress data */
- if ( ( rc = deflate_inflate ( deflate, in, &out ) ) != 0 ) {
+ if ( ( rc = deflate_inflate ( deflate, data, len,
+ &out ) ) != 0 ) {
DBGC ( extracted, "ZLIB %p could not decompress: %s\n",
extracted, strerror ( rc ) );
goto err_inflate;
@@ -116,14 +114,11 @@ int zlib_deflate ( enum deflate_format format, struct deflate_chunk *in,
* @ret rc Return status code
*/
static int zlib_extract ( struct image *image, struct image *extracted ) {
- struct deflate_chunk in;
int rc;
- /* Initialise input chunk */
- deflate_chunk_init ( &in, image->data, 0, image->len );
-
/* Decompress image */
- if ( ( rc = zlib_deflate ( DEFLATE_ZLIB, &in, extracted ) ) != 0 )
+ if ( ( rc = zlib_deflate ( DEFLATE_ZLIB, image->data, image->len,
+ extracted ) ) != 0 )
return rc;
return 0;
@@ -136,17 +131,17 @@ static int zlib_extract ( struct image *image, struct image *extracted ) {
* @ret rc Return status code
*/
static int zlib_probe ( struct image *image ) {
- union zlib_magic magic;
+ const union zlib_magic *magic;
/* Sanity check */
- if ( image->len < sizeof ( magic ) ) {
+ if ( image->len < sizeof ( *magic ) ) {
DBGC ( image, "ZLIB %p image too short\n", image );
return -ENOEXEC;
}
+ magic = image->data;
/* Check magic header */
- copy_from_user ( &magic, image->data, 0, sizeof ( magic ) );
- if ( ! zlib_magic_is_valid ( &magic ) ) {
+ if ( ! zlib_magic_is_valid ( magic ) ) {
DBGC ( image, "ZLIB %p invalid magic data\n", image );
return -ENOEXEC;
}