Merge commit 'd7bde18da2a8a81f2d5f256bc975b1fb5b546107' into dev

This commit is contained in:
Théophile Diot 2023-09-15 14:10:28 +02:00
commit 6752b36471
No known key found for this signature in database
GPG key ID: 248FEA4BAE400D06
3 changed files with 98 additions and 23 deletions

View file

@ -0,0 +1,57 @@
name: Tests
on:
pull_request:
paths-ignore:
- '*.md'
push:
branches:
- master
- release/*
paths-ignore:
- '*.md'
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
tests:
name: Tests
runs-on: ubuntu-latest
container:
image: openresty/openresty:${{ matrix.openresty }}-jammy
strategy:
fail-fast: false
matrix:
openresty: ["1.19.9.1-14", "1.21.4.1-0"]
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Install valgrind
run: |
apt-get update
apt-get install -y valgrind
# ensure the library works even without dev packages installed (libz.so.1 instead of libz.so)
- name: Remove dev packages
run: |
apt-get purge -y libc-dev-bin
- name: Run test with LuaJIT
run: |
luajit test.lua /usr/local/openresty/nginx/sbin/nginx 65536000
- name: Run test with resty-cli
run: |
resty --no-stream test.lua /usr/local/openresty/nginx/sbin/nginx 65536000
- name: Run test with resty-cli (valgrind)
if: contains(matrix.extras, 'valgrind')
run: |
resty --no-stream --valgrind test.lua /usr/local/openresty/nginx/sbin/nginx 65536000

View file

@ -95,11 +95,11 @@ unsigned long crc32_combine(unsigned long, unsigned long, long);
]])
local zlib = ffi.load("/usr/share/bunkerweb/deps/lib/lua/libz.so")
_M.zlib = zlib
local zlib = ffi.load("/usr/share/bunkerweb/deps/lib/lua/libz.so")
_M.zlib = zlib
-- Default to 16k output buffer
local DEFAULT_CHUNK = 16384
local DEFAULT_CHUNK = 16384
local Z_OK = zlib.Z_OK
local Z_NO_FLUSH = zlib.Z_NO_FLUSH
@ -119,7 +119,7 @@ local function createStream(bufsize)
local stream = ffi_new("z_stream")
-- Create input buffer var
local inbuf = ffi_new('char[?]', bufsize+1)
local inbuf = ffi_new('char[?]', bufsize + 1)
stream.next_in, stream.avail_in = inbuf, 0
-- create the output buffer
@ -142,9 +142,9 @@ _M.initInflate = initInflate
local function initDeflate(stream, options)
-- Setup deflate process
local method = zlib.Z_DEFLATED
local level = options.level or zlib.Z_DEFAULT_COMPRESSION
local memLevel = options.memLevel or 8
local strategy = options.strategy or zlib.Z_DEFAULT_STRATEGY
local level = options.level or zlib.Z_DEFAULT_COMPRESSION
local memLevel = options.memLevel or 8
local strategy = options.strategy or zlib.Z_DEFAULT_STRATEGY
local windowBits = options.windowBits or (15 + 16) -- +16 sets gzip wrapper not zlib
local version = ffi_str(zlib.zlibVersion())
@ -192,25 +192,24 @@ local function inflate(input, output, bufsize, stream, inbuf, outbuf)
stream.next_out = outbuf
stream.avail_out = bufsize
-- Process the stream, always Z_NO_FLUSH in inflate mode
err = zlib_flate(stream, Z_NO_FLUSH)
err = zlib_flate(stream, Z_NO_FLUSH)
-- Buffer errors are OK here
if err == Z_BUF_ERROR then
err = Z_OK
end
if err < Z_OK or err == Z_NEED_DICT then
-- Error, clean up and return
zlib_flateEnd(stream)
return false, "INFLATE: "..zlib_err(err), stream
-- Error, clean up and return
zlib_flateEnd(stream)
return false, "INFLATE: " .. zlib_err(err), stream
end
-- Write the data out
local err = flushOutput(stream, bufsize, output, outbuf)
if err then
zlib_flateEnd(stream)
return false, "INFLATE: "..err
zlib_flateEnd(stream)
return false, "INFLATE: " .. err
end
until stream.avail_out ~= 0
until err == Z_STREAM_END
-- Stream finished, clean up and return
@ -244,19 +243,19 @@ local function deflate(input, output, bufsize, stream, inbuf, outbuf)
stream.avail_out = bufsize
-- Process the stream
err = zlib_flate(stream, mode)
err = zlib_flate(stream, mode)
-- Only possible *bad* return value here
if err == Z_STREAM_ERROR then
-- Error, clean up and return
zlib_flateEnd(stream)
return false, "DEFLATE: "..zlib_err(err), stream
-- Error, clean up and return
zlib_flateEnd(stream)
return false, "DEFLATE: " .. zlib_err(err), stream
end
-- Write the data out
local err = flushOutput(stream, bufsize, output, outbuf)
if err then
zlib_flateEnd(stream)
return false, "DEFLATE: "..err
zlib_flateEnd(stream)
return false, "DEFLATE: " .. err
end
until stream.avail_out ~= 0
@ -265,7 +264,6 @@ local function deflate(input, output, bufsize, stream, inbuf, outbuf)
zlib_flateEnd(stream)
return false, "DEFLATE: Input not used"
end
until err == Z_STREAM_END
-- Stream finished, clean up and return
@ -301,7 +299,7 @@ function _M.inflateGzip(input, output, bufsize, windowBits)
else
-- Init error
zlib.inflateEnd(stream)
return false, "INIT: "..zlib_err(init)
return false, "INIT: " .. zlib_err(init)
end
end
@ -319,7 +317,7 @@ function _M.deflateGzip(input, output, bufsize, options)
else
-- Init error
zlib.deflateEnd(stream)
return false, "INIT: "..zlib_err(init)
return false, "INIT: " .. zlib_err(init)
end
end

View file

@ -0,0 +1,20 @@
package = "lua-ffi-zlib"
version = "0.6-0"
source = {
url = "git://github.com/hamishforbes/lua-ffi-zlib",
tag = "v0.6"
}
description = {
summary = "A Lua module using LuaJIT's FFI feature to access zlib.",
homepage = "https://github.com/hamishforbes/lua-ffi-zlib",
maintainer = "Hamish Forbes"
}
dependencies = {
"lua >= 5.1",
}
build = {
type = "builtin",
modules = {
["ffi-zlib"] = "lib/ffi-zlib.lua",
}
}