Compare commits

..
17 Commits
Author SHA1 Message Date
Nigel Tao b69ebf4606 wuffs gen -version=0.3.6 2026-10-20 14:29:37 +11:00
Nigel Tao 5527993842 lib: fix "go test" example names
This backports commit 689f84213f from the
main branch (working on an unstable v0.4) to the v0.3 branch.
2026-10-20 14:25:29 +11:00
Nigel Tao 32a23a9bb5 base: backport parse_number_{u64,f64} fixes
This backports commits 9d41525a2f and
c99f5af9fe from the main branch (working
on an unstable v0.4) to the v0.3 branch.
2026-10-20 14:17:58 +11:00
Nigel Tao d1a6f2c3de wuffs gen -version=0.3.5 2026-07-11 20:37:47 +10:00
Nigel Tao 40445d992b mimiclib: #include <limits.h> and <stdint.h>
This backports commit 39baf44c19d0759c42853f5e7d72bd1ba0070321 from the
main branch (working on an unstable v0.4) to the v0.3 branch.
2026-07-11 20:36:12 +10:00
Nigel Tao e7b15476b8 test/data: rename non-ascii/😻.txt
This backports commit 7250990196 from the
main branch (working on an unstable v0.4) to the v0.3 branch.
2026-07-11 20:33:41 +10:00
Nigel Tao ec71f9c6d8 wuffs gen -version=0.3.4 2024-04-19 21:44:35 +10:00
Nigel Tao a138188d57 std/png: ignore tRNS chunks for color types 4, 6
This backports commit da0d51d802 from the
main branch (working on an unstable v0.4) to the v0.3 branch.

Updates #146
2024-04-19 21:41:16 +10:00
Nigel Tao d910658bce wuffs gen -version=0.3.3 2023-04-08 14:57:52 +10:00
Nigel Tao 00d5e35865 floatconv: optimize parse_number_f64 fallback
The time taken running script/manual-test-parse-number-f64.cc on the
parse-number-fxx-test-data suite falls from 3.565s to 2.491s (a 1.43x
ratio; the inverse is 0.70 = 100% - 30%).

Fixes #113
2023-04-08 14:56:32 +10:00
Nigel Tao 05f0172b93 script/manual-test-truncated-input: re-enable WBMP 2023-04-07 16:06:09 +10:00
Nigel Tao 57bd11bf39 wuffs gen -version=0.3.2 2023-04-07 13:53:11 +10:00
Nigel Tao 67d9a68c49 Update doc/changelog.md for v0.3.2 2023-04-07 13:52:02 +10:00
Nigel Tao 17f7613262 std/{bmp,nie}: allow decode_frame to small pixbuf 2023-03-27 21:22:06 +11:00
Nigel Tao baac49dca7 script: add manual-test-truncated-input.cc
Updates #96
2023-03-27 21:15:38 +11:00
Nigel Tao a12a807d0e script/print-image-metadata: fix infinite loop
Fixes #107
2023-03-18 14:49:50 +11:00
Nigel Tao 000b0a3445 std/png: decode "truncated input" for short chunks
Updates #101
2023-03-12 19:23:41 +11:00
21 changed files with 1021 additions and 274 deletions

No files matched your search

+19 -2
View File
@@ -1,7 +1,24 @@
# Changelog
## Work In Progress
## 2024-04-19 version 0.3.4
- Have `std/png` ignore tRNS chunks for color types 4 (YA) and 6 (RGBA).
## 2023-04-08 version 0.3.3
The `wuffs_base__parse_number_f64` function has been further optimized.
## 2023-04-07 version 0.3.2
The `std/bmp` and `std/nie` image decoders' `decode_frame` method now allow
decoding to a pixel buffer that's smaller than the source image. This makes
these two image decoders consistent with the other ones in `std`.
## 2023-03-04 version 0.3.1
For a *closed* `io_reader`, the standard library now returns `"#truncated
input"` instead of `"$short read"`. Importantly, this is an error, not a
@@ -175,4 +192,4 @@ Wuffs version 0.1.
---
Updated on January 2023.
Updated on April 2023.
+47 -33
View File
@@ -276,14 +276,12 @@ wuffs_base__private_implementation__high_prec_dec__parse(
uint8_t* q = s.ptr + s.len;
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
for (;; p++) {
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
} else if (*p != '_') {
break;
}
for (; (p < q) && (*p == '_'); p++) {
}
}
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
// Parse sign.
do {
@@ -296,14 +294,12 @@ wuffs_base__private_implementation__high_prec_dec__parse(
break;
}
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
for (;; p++) {
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
} else if (*p != '_') {
break;
}
for (; (p < q) && (*p == '_'); p++) {
}
}
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
} while (0);
// Parse digits, up to (and including) a '.', 'E' or 'e'. Examples for each
@@ -355,9 +351,12 @@ wuffs_base__private_implementation__high_prec_dec__parse(
if (nd < WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION) {
h->digits[nd++] = (uint8_t)(*p - '0');
dp = (int32_t)nd;
} else if ('0' != *p) {
// Long-tail non-zeroes set the truncated bit.
h->truncated = true;
} else {
dp++;
if ('0' != *p) {
// Long-tail non-zeroes set the truncated bit.
h->truncated = true;
}
}
} else if (*p ==
((options &
@@ -417,14 +416,12 @@ after_sep:
after_exp:
do {
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
for (;; p++) {
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
} else if (*p != '_') {
break;
}
for (; (p < q) && (*p == '_'); p++) {
}
}
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
int32_t exp_sign = +1;
if (*p == '+') {
@@ -1304,24 +1301,41 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
// approach taken in wuffs_base__parse_number_f64. The latter is optimized
// for the common cases (e.g. assuming no underscores or a leading '+'
// sign) rather than the full set of cases allowed by the Wuffs API.
if (h->num_digits <= 19) {
//
// When we have 19 or fewer mantissa digits, run Eisel-Lemire once (trying
// for an exact result). When we have more than 19 mantissa digits, run it
// twice to get a lower and upper bound. We still have an exact result
// (within f64's rounding margin) if both bounds are equal (and valid).
uint32_t i_max = h->num_digits;
if (i_max > 19) {
i_max = 19;
}
int32_t exp10 = h->decimal_point - ((int32_t)i_max);
if ((-307 <= exp10) && (exp10 <= 288)) {
uint64_t man = 0;
uint32_t i;
for (i = 0; i < h->num_digits; i++) {
for (i = 0; i < i_max; i++) {
man = (10 * man) + h->digits[i];
}
int32_t exp10 = h->decimal_point - ((int32_t)(h->num_digits));
if ((man != 0) && (-307 <= exp10) && (exp10 <= 288)) {
int64_t r =
while (man != 0) { // The 'while' is just an 'if' that we can 'break'.
int64_t r0 =
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
man, exp10);
if (r >= 0) {
wuffs_base__result_f64 ret;
ret.status.repr = NULL;
ret.value = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
((uint64_t)r) | (((uint64_t)(h->negative)) << 63));
return ret;
man + 0, exp10);
if (r0 < 0) {
break;
} else if (h->num_digits > 19) {
int64_t r1 =
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
man + 1, exp10);
if (r1 != r0) {
break;
}
}
wuffs_base__result_f64 ret;
ret.status.repr = NULL;
ret.value = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
((uint64_t)r0) | (((uint64_t)(h->negative)) << 63));
return ret;
}
}
+2
View File
@@ -219,6 +219,7 @@ wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {
if (p < q) {
goto hexadecimal;
}
goto fail_bad_argument;
} else if ((*p == 'd') || (*p == 'D')) {
p++;
@@ -229,6 +230,7 @@ wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {
if (p < q) {
goto decimal;
}
goto fail_bad_argument;
}
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES) {
+2 -2
View File
@@ -21,7 +21,7 @@ import (
"github.com/google/wuffs/lib/litonlylzma"
)
func ExampleRoundTripLZMA() {
func Example_roundTripLZMA() {
original := []byte("Hello world.\n")
compressed, err := litonlylzma.FileFormatLZMA.Encode(nil, original)
if err != nil {
@@ -49,7 +49,7 @@ func ExampleRoundTripLZMA() {
// Hello world.
}
func ExampleRoundTripXz() {
func Example_roundTripXz() {
original := []byte("Hello world.\n")
compressed, err := litonlylzma.FileFormatXz.Encode(nil, original)
if err != nil {
+1 -1
View File
@@ -25,7 +25,7 @@ import (
"github.com/google/wuffs/lib/zlibcut"
)
func ExampleCut() {
func Example() {
const sonnet18 = "" +
"Shall I compare thee to a summer’s day?\n" +
"Thou art more lovely and more temperate.\n" +
+169 -85
View File
@@ -13793,14 +13793,12 @@ wuffs_base__private_implementation__high_prec_dec__parse(
uint8_t* q = s.ptr + s.len;
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
for (;; p++) {
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
} else if (*p != '_') {
break;
}
for (; (p < q) && (*p == '_'); p++) {
}
}
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
// Parse sign.
do {
@@ -13813,14 +13811,12 @@ wuffs_base__private_implementation__high_prec_dec__parse(
break;
}
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
for (;; p++) {
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
} else if (*p != '_') {
break;
}
for (; (p < q) && (*p == '_'); p++) {
}
}
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
} while (0);
// Parse digits, up to (and including) a '.', 'E' or 'e'. Examples for each
@@ -13872,9 +13868,12 @@ wuffs_base__private_implementation__high_prec_dec__parse(
if (nd < WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION) {
h->digits[nd++] = (uint8_t)(*p - '0');
dp = (int32_t)nd;
} else if ('0' != *p) {
// Long-tail non-zeroes set the truncated bit.
h->truncated = true;
} else {
dp++;
if ('0' != *p) {
// Long-tail non-zeroes set the truncated bit.
h->truncated = true;
}
}
} else if (*p ==
((options &
@@ -13934,14 +13933,12 @@ after_sep:
after_exp:
do {
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
for (;; p++) {
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
} else if (*p != '_') {
break;
}
for (; (p < q) && (*p == '_'); p++) {
}
}
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
int32_t exp_sign = +1;
if (*p == '+') {
@@ -14821,24 +14818,41 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
// approach taken in wuffs_base__parse_number_f64. The latter is optimized
// for the common cases (e.g. assuming no underscores or a leading '+'
// sign) rather than the full set of cases allowed by the Wuffs API.
if (h->num_digits <= 19) {
//
// When we have 19 or fewer mantissa digits, run Eisel-Lemire once (trying
// for an exact result). When we have more than 19 mantissa digits, run it
// twice to get a lower and upper bound. We still have an exact result
// (within f64's rounding margin) if both bounds are equal (and valid).
uint32_t i_max = h->num_digits;
if (i_max > 19) {
i_max = 19;
}
int32_t exp10 = h->decimal_point - ((int32_t)i_max);
if ((-307 <= exp10) && (exp10 <= 288)) {
uint64_t man = 0;
uint32_t i;
for (i = 0; i < h->num_digits; i++) {
for (i = 0; i < i_max; i++) {
man = (10 * man) + h->digits[i];
}
int32_t exp10 = h->decimal_point - ((int32_t)(h->num_digits));
if ((man != 0) && (-307 <= exp10) && (exp10 <= 288)) {
int64_t r =
while (man != 0) { // The 'while' is just an 'if' that we can 'break'.
int64_t r0 =
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
man, exp10);
if (r >= 0) {
wuffs_base__result_f64 ret;
ret.status.repr = NULL;
ret.value = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
((uint64_t)r) | (((uint64_t)(h->negative)) << 63));
return ret;
man + 0, exp10);
if (r0 < 0) {
break;
} else if (h->num_digits > 19) {
int64_t r1 =
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
man + 1, exp10);
if (r1 != r0) {
break;
}
}
wuffs_base__result_f64 ret;
ret.status.repr = NULL;
ret.value = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
((uint64_t)r0) | (((uint64_t)(h->negative)) << 63));
return ret;
}
}
@@ -15733,6 +15747,7 @@ wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {
if (p < q) {
goto hexadecimal;
}
goto fail_bad_argument;
} else if ((*p == 'd') || (*p == 'D')) {
p++;
@@ -15743,6 +15758,7 @@ wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {
if (p < q) {
goto decimal;
}
goto fail_bad_argument;
}
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES) {
@@ -24195,10 +24211,12 @@ wuffs_bmp__decoder__swizzle_none(
uint32_t v_dst_bits_per_pixel = 0;
uint64_t v_dst_bytes_per_pixel = 0;
uint64_t v_dst_bytes_per_row = 0;
uint32_t v_src_bytes_per_pixel = 0;
wuffs_base__slice_u8 v_dst_palette = {0};
wuffs_base__table_u8 v_tab = {0};
wuffs_base__slice_u8 v_dst = {0};
uint64_t v_i = 0;
uint64_t v_j = 0;
uint64_t v_n = 0;
const uint8_t* iop_a_src = NULL;
@@ -24232,7 +24250,6 @@ wuffs_bmp__decoder__swizzle_none(
self->private_impl.f_pending_pad -= 1;
iop_a_src += 1;
}
label__inner__continue:;
while (true) {
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
self->private_impl.f_dst_x = 0;
@@ -24253,14 +24270,38 @@ wuffs_bmp__decoder__swizzle_none(
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
if (v_i >= ((uint64_t)(v_dst.len))) {
goto label__inner__continue;
if (self->private_impl.f_bits_per_pixel > 32) {
status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file);
goto exit;
}
v_src_bytes_per_pixel = (self->private_impl.f_bits_per_pixel / 8);
if (v_src_bytes_per_pixel == 0) {
status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file);
goto exit;
}
v_n = (((uint64_t)(io2_a_src - iop_a_src)) / ((uint64_t)(v_src_bytes_per_pixel)));
v_n = wuffs_base__u64__min(v_n, ((uint64_t)(((uint32_t)(self->private_impl.f_width - self->private_impl.f_dst_x)))));
v_j = v_n;
while (v_j >= 8) {
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 8)))) {
iop_a_src += (v_src_bytes_per_pixel * 8);
}
v_j -= 8;
}
while (v_j > 0) {
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 1)))) {
iop_a_src += (v_src_bytes_per_pixel * 1);
}
v_j -= 1;
}
} else {
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
&self->private_impl.f_swizzler,
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
v_dst_palette,
&iop_a_src,
io2_a_src);
}
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
&self->private_impl.f_swizzler,
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
v_dst_palette,
&iop_a_src,
io2_a_src);
if (v_n == 0) {
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
goto ok;
@@ -24601,7 +24642,6 @@ wuffs_bmp__decoder__swizzle_bitfields(
self->private_impl.f_pending_pad -= 1;
iop_a_src += 1;
}
label__inner__continue:;
while (true) {
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
self->private_impl.f_dst_x = 0;
@@ -24660,9 +24700,10 @@ wuffs_bmp__decoder__swizzle_bitfields(
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
if (v_i >= ((uint64_t)(v_dst.len))) {
goto label__inner__continue;
v_n = ((uint64_t)(v_p0));
} else {
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, (8 * v_p0)));
}
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, (8 * v_p0)));
if (v_n == 0) {
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
goto ok;
@@ -24705,6 +24746,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
uint32_t v_p0 = 0;
uint32_t v_chunk_bits = 0;
uint32_t v_chunk_count = 0;
uint32_t v_pixels_per_chunk = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
@@ -24742,6 +24784,35 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
if (v_i >= ((uint64_t)(v_dst.len))) {
if (self->private_impl.f_bits_per_pixel == 1) {
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 31) / 32);
v_pixels_per_chunk = 32;
} else if (self->private_impl.f_bits_per_pixel == 2) {
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 15) / 16);
v_pixels_per_chunk = 16;
} else {
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 7) / 8);
v_pixels_per_chunk = 8;
}
while ((v_chunk_count >= 64) && (((uint64_t)(io2_a_src - iop_a_src)) >= 256)) {
iop_a_src += 256;
self->private_impl.f_dst_x = wuffs_base__u32__min(self->private_impl.f_width, ((uint32_t)(self->private_impl.f_dst_x + (v_pixels_per_chunk * 64))));
v_chunk_count -= 64;
}
while ((v_chunk_count >= 8) && (((uint64_t)(io2_a_src - iop_a_src)) >= 32)) {
iop_a_src += 32;
self->private_impl.f_dst_x = wuffs_base__u32__min(self->private_impl.f_width, ((uint32_t)(self->private_impl.f_dst_x + (v_pixels_per_chunk * 8))));
v_chunk_count -= 8;
}
while (v_chunk_count > 0) {
if (((uint64_t)(io2_a_src - iop_a_src)) < 4) {
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
goto ok;
}
iop_a_src += 4;
self->private_impl.f_dst_x = wuffs_base__u32__min(self->private_impl.f_width, ((uint32_t)(self->private_impl.f_dst_x + (v_pixels_per_chunk * 1))));
v_chunk_count -= 1;
}
goto label__loop__continue;
}
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_i);
@@ -24812,7 +24883,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
v_p0 = ((v_p0 & 511) + 16);
v_chunk_count -= 1;
}
} else if (self->private_impl.f_bits_per_pixel == 4) {
} else {
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 7) / 8);
v_chunk_count = wuffs_base__u32__min(v_chunk_count, 64);
while ((v_chunk_count > 0) && (((uint64_t)(io2_a_src - iop_a_src)) >= 4)) {
@@ -37894,9 +37965,11 @@ wuffs_nie__decoder__swizzle(
uint32_t v_dst_bits_per_pixel = 0;
uint64_t v_dst_bytes_per_pixel = 0;
uint64_t v_dst_bytes_per_row = 0;
uint32_t v_src_bytes_per_pixel = 0;
wuffs_base__table_u8 v_tab = {0};
wuffs_base__slice_u8 v_dst = {0};
uint64_t v_i = 0;
uint64_t v_j = 0;
uint64_t v_n = 0;
const uint8_t* iop_a_src = NULL;
@@ -37919,7 +37992,6 @@ wuffs_nie__decoder__swizzle(
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
label__0__continue:;
while (true) {
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
self->private_impl.f_dst_x = 0;
@@ -37934,14 +38006,33 @@ wuffs_nie__decoder__swizzle(
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
if (v_i >= ((uint64_t)(v_dst.len))) {
goto label__0__continue;
v_src_bytes_per_pixel = 4;
if (self->private_impl.f_pixfmt == 2164308923) {
v_src_bytes_per_pixel = 8;
}
v_n = (((uint64_t)(io2_a_src - iop_a_src)) / ((uint64_t)(v_src_bytes_per_pixel)));
v_n = wuffs_base__u64__min(v_n, ((uint64_t)(((uint32_t)(self->private_impl.f_width - self->private_impl.f_dst_x)))));
v_j = v_n;
while (v_j >= 8) {
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 8)))) {
iop_a_src += (v_src_bytes_per_pixel * 8);
}
v_j -= 8;
}
while (v_j > 0) {
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 1)))) {
iop_a_src += (v_src_bytes_per_pixel * 1);
}
v_j -= 1;
}
} else {
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
&self->private_impl.f_swizzler,
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
wuffs_base__pixel_buffer__palette(a_dst),
&iop_a_src,
io2_a_src);
}
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
&self->private_impl.f_swizzler,
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
wuffs_base__pixel_buffer__palette(a_dst),
&iop_a_src,
io2_a_src);
if (v_n == 0) {
status = wuffs_base__make_status(wuffs_nie__note__internal_note_short_read);
goto ok;
@@ -40795,14 +40886,12 @@ wuffs_png__decoder__do_decode_image_config(
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
goto ok;
}
label__1__continue:;
while (true) {
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
if (a_src && a_src->meta.closed) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
goto label__1__continue;
}
self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32)));
@@ -41478,20 +41567,22 @@ wuffs_png__decoder__decode_other_chunk(
self->private_impl.f_seen_srgb = true;
}
} else if (self->private_impl.f_chunk_type == 1397641844) {
if (self->private_impl.f_seen_trns || (self->private_impl.f_color_type > 3) || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
if (self->private_impl.f_seen_trns || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
status = wuffs_png__decoder__decode_trns(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
} else if (self->private_impl.f_color_type > 3) {
} else {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
status = wuffs_png__decoder__decode_trns(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
}
self->private_impl.f_seen_trns = true;
}
@@ -43201,13 +43292,10 @@ wuffs_png__decoder__skip_frame(
self->private_impl.f_chunk_type_array[3] = 0;
label__0__continue:;
while (true) {
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
if (a_src && a_src->meta.closed) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
goto label__0__continue;
}
self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32)));
@@ -43446,14 +43534,12 @@ wuffs_png__decoder__do_decode_frame(
goto suspend;
}
}
label__0__continue:;
while (true) {
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
if (a_src && a_src->meta.closed) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
goto label__0__continue;
}
self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32)));
@@ -43588,14 +43674,12 @@ wuffs_png__decoder__do_decode_frame(
wuffs_png__decoder__filter_and_swizzle(self, a_dst, wuffs_base__slice_u8__subslice_j(a_workbuf, self->private_impl.f_workbuf_wi));
}
if (v_status.repr == wuffs_base__suspension__short_read) {
while (true) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
}
status = wuffs_base__make_status(wuffs_png__error__truncated_input);
goto exit;
}
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
}
label__1__break:;
v_status = wuffs_png__decoder__filter_and_swizzle(self, a_dst, a_workbuf);
+175 -91
View File
@@ -85,15 +85,15 @@ extern "C" {
// each major.minor branch, the commit count should increase monotonically.
//
// WUFFS_VERSION was overridden by "wuffs gen -version" based on revision
// 02844cdca44276c1838ab15f5b73f901345d5ead committed on 2023-02-23.
#define WUFFS_VERSION 0x000030001
// 55279938422060f30cd487173b98a651da075e3a committed on 2026-10-20.
#define WUFFS_VERSION 0x000030006
#define WUFFS_VERSION_MAJOR 0
#define WUFFS_VERSION_MINOR 3
#define WUFFS_VERSION_PATCH 1
#define WUFFS_VERSION_PATCH 6
#define WUFFS_VERSION_PRE_RELEASE_LABEL ""
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3390
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20230223
#define WUFFS_VERSION_STRING "0.3.1+3390.20230223"
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3407
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20261020
#define WUFFS_VERSION_STRING "0.3.6+3407.20261020"
// ---------------- Configuration
@@ -13794,14 +13794,12 @@ wuffs_base__private_implementation__high_prec_dec__parse(
uint8_t* q = s.ptr + s.len;
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
for (;; p++) {
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
} else if (*p != '_') {
break;
}
for (; (p < q) && (*p == '_'); p++) {
}
}
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
// Parse sign.
do {
@@ -13814,14 +13812,12 @@ wuffs_base__private_implementation__high_prec_dec__parse(
break;
}
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
for (;; p++) {
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
} else if (*p != '_') {
break;
}
for (; (p < q) && (*p == '_'); p++) {
}
}
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
} while (0);
// Parse digits, up to (and including) a '.', 'E' or 'e'. Examples for each
@@ -13873,9 +13869,12 @@ wuffs_base__private_implementation__high_prec_dec__parse(
if (nd < WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION) {
h->digits[nd++] = (uint8_t)(*p - '0');
dp = (int32_t)nd;
} else if ('0' != *p) {
// Long-tail non-zeroes set the truncated bit.
h->truncated = true;
} else {
dp++;
if ('0' != *p) {
// Long-tail non-zeroes set the truncated bit.
h->truncated = true;
}
}
} else if (*p ==
((options &
@@ -13935,14 +13934,12 @@ after_sep:
after_exp:
do {
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
for (;; p++) {
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
} else if (*p != '_') {
break;
}
for (; (p < q) && (*p == '_'); p++) {
}
}
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
int32_t exp_sign = +1;
if (*p == '+') {
@@ -14822,24 +14819,41 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
// approach taken in wuffs_base__parse_number_f64. The latter is optimized
// for the common cases (e.g. assuming no underscores or a leading '+'
// sign) rather than the full set of cases allowed by the Wuffs API.
if (h->num_digits <= 19) {
//
// When we have 19 or fewer mantissa digits, run Eisel-Lemire once (trying
// for an exact result). When we have more than 19 mantissa digits, run it
// twice to get a lower and upper bound. We still have an exact result
// (within f64's rounding margin) if both bounds are equal (and valid).
uint32_t i_max = h->num_digits;
if (i_max > 19) {
i_max = 19;
}
int32_t exp10 = h->decimal_point - ((int32_t)i_max);
if ((-307 <= exp10) && (exp10 <= 288)) {
uint64_t man = 0;
uint32_t i;
for (i = 0; i < h->num_digits; i++) {
for (i = 0; i < i_max; i++) {
man = (10 * man) + h->digits[i];
}
int32_t exp10 = h->decimal_point - ((int32_t)(h->num_digits));
if ((man != 0) && (-307 <= exp10) && (exp10 <= 288)) {
int64_t r =
while (man != 0) { // The 'while' is just an 'if' that we can 'break'.
int64_t r0 =
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
man, exp10);
if (r >= 0) {
wuffs_base__result_f64 ret;
ret.status.repr = NULL;
ret.value = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
((uint64_t)r) | (((uint64_t)(h->negative)) << 63));
return ret;
man + 0, exp10);
if (r0 < 0) {
break;
} else if (h->num_digits > 19) {
int64_t r1 =
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
man + 1, exp10);
if (r1 != r0) {
break;
}
}
wuffs_base__result_f64 ret;
ret.status.repr = NULL;
ret.value = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
((uint64_t)r0) | (((uint64_t)(h->negative)) << 63));
return ret;
}
}
@@ -15734,6 +15748,7 @@ wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {
if (p < q) {
goto hexadecimal;
}
goto fail_bad_argument;
} else if ((*p == 'd') || (*p == 'D')) {
p++;
@@ -15744,6 +15759,7 @@ wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {
if (p < q) {
goto decimal;
}
goto fail_bad_argument;
}
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES) {
@@ -24196,10 +24212,12 @@ wuffs_bmp__decoder__swizzle_none(
uint32_t v_dst_bits_per_pixel = 0;
uint64_t v_dst_bytes_per_pixel = 0;
uint64_t v_dst_bytes_per_row = 0;
uint32_t v_src_bytes_per_pixel = 0;
wuffs_base__slice_u8 v_dst_palette = {0};
wuffs_base__table_u8 v_tab = {0};
wuffs_base__slice_u8 v_dst = {0};
uint64_t v_i = 0;
uint64_t v_j = 0;
uint64_t v_n = 0;
const uint8_t* iop_a_src = NULL;
@@ -24233,7 +24251,6 @@ wuffs_bmp__decoder__swizzle_none(
self->private_impl.f_pending_pad -= 1;
iop_a_src += 1;
}
label__inner__continue:;
while (true) {
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
self->private_impl.f_dst_x = 0;
@@ -24254,14 +24271,38 @@ wuffs_bmp__decoder__swizzle_none(
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
if (v_i >= ((uint64_t)(v_dst.len))) {
goto label__inner__continue;
if (self->private_impl.f_bits_per_pixel > 32) {
status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file);
goto exit;
}
v_src_bytes_per_pixel = (self->private_impl.f_bits_per_pixel / 8);
if (v_src_bytes_per_pixel == 0) {
status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file);
goto exit;
}
v_n = (((uint64_t)(io2_a_src - iop_a_src)) / ((uint64_t)(v_src_bytes_per_pixel)));
v_n = wuffs_base__u64__min(v_n, ((uint64_t)(((uint32_t)(self->private_impl.f_width - self->private_impl.f_dst_x)))));
v_j = v_n;
while (v_j >= 8) {
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 8)))) {
iop_a_src += (v_src_bytes_per_pixel * 8);
}
v_j -= 8;
}
while (v_j > 0) {
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 1)))) {
iop_a_src += (v_src_bytes_per_pixel * 1);
}
v_j -= 1;
}
} else {
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
&self->private_impl.f_swizzler,
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
v_dst_palette,
&iop_a_src,
io2_a_src);
}
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
&self->private_impl.f_swizzler,
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
v_dst_palette,
&iop_a_src,
io2_a_src);
if (v_n == 0) {
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
goto ok;
@@ -24602,7 +24643,6 @@ wuffs_bmp__decoder__swizzle_bitfields(
self->private_impl.f_pending_pad -= 1;
iop_a_src += 1;
}
label__inner__continue:;
while (true) {
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
self->private_impl.f_dst_x = 0;
@@ -24661,9 +24701,10 @@ wuffs_bmp__decoder__swizzle_bitfields(
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
if (v_i >= ((uint64_t)(v_dst.len))) {
goto label__inner__continue;
v_n = ((uint64_t)(v_p0));
} else {
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, (8 * v_p0)));
}
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, (8 * v_p0)));
if (v_n == 0) {
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
goto ok;
@@ -24706,6 +24747,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
uint32_t v_p0 = 0;
uint32_t v_chunk_bits = 0;
uint32_t v_chunk_count = 0;
uint32_t v_pixels_per_chunk = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
@@ -24743,6 +24785,35 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
if (v_i >= ((uint64_t)(v_dst.len))) {
if (self->private_impl.f_bits_per_pixel == 1) {
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 31) / 32);
v_pixels_per_chunk = 32;
} else if (self->private_impl.f_bits_per_pixel == 2) {
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 15) / 16);
v_pixels_per_chunk = 16;
} else {
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 7) / 8);
v_pixels_per_chunk = 8;
}
while ((v_chunk_count >= 64) && (((uint64_t)(io2_a_src - iop_a_src)) >= 256)) {
iop_a_src += 256;
self->private_impl.f_dst_x = wuffs_base__u32__min(self->private_impl.f_width, ((uint32_t)(self->private_impl.f_dst_x + (v_pixels_per_chunk * 64))));
v_chunk_count -= 64;
}
while ((v_chunk_count >= 8) && (((uint64_t)(io2_a_src - iop_a_src)) >= 32)) {
iop_a_src += 32;
self->private_impl.f_dst_x = wuffs_base__u32__min(self->private_impl.f_width, ((uint32_t)(self->private_impl.f_dst_x + (v_pixels_per_chunk * 8))));
v_chunk_count -= 8;
}
while (v_chunk_count > 0) {
if (((uint64_t)(io2_a_src - iop_a_src)) < 4) {
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
goto ok;
}
iop_a_src += 4;
self->private_impl.f_dst_x = wuffs_base__u32__min(self->private_impl.f_width, ((uint32_t)(self->private_impl.f_dst_x + (v_pixels_per_chunk * 1))));
v_chunk_count -= 1;
}
goto label__loop__continue;
}
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_i);
@@ -24813,7 +24884,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
v_p0 = ((v_p0 & 511) + 16);
v_chunk_count -= 1;
}
} else if (self->private_impl.f_bits_per_pixel == 4) {
} else {
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 7) / 8);
v_chunk_count = wuffs_base__u32__min(v_chunk_count, 64);
while ((v_chunk_count > 0) && (((uint64_t)(io2_a_src - iop_a_src)) >= 4)) {
@@ -37895,9 +37966,11 @@ wuffs_nie__decoder__swizzle(
uint32_t v_dst_bits_per_pixel = 0;
uint64_t v_dst_bytes_per_pixel = 0;
uint64_t v_dst_bytes_per_row = 0;
uint32_t v_src_bytes_per_pixel = 0;
wuffs_base__table_u8 v_tab = {0};
wuffs_base__slice_u8 v_dst = {0};
uint64_t v_i = 0;
uint64_t v_j = 0;
uint64_t v_n = 0;
const uint8_t* iop_a_src = NULL;
@@ -37920,7 +37993,6 @@ wuffs_nie__decoder__swizzle(
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
label__0__continue:;
while (true) {
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
self->private_impl.f_dst_x = 0;
@@ -37935,14 +38007,33 @@ wuffs_nie__decoder__swizzle(
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
if (v_i >= ((uint64_t)(v_dst.len))) {
goto label__0__continue;
v_src_bytes_per_pixel = 4;
if (self->private_impl.f_pixfmt == 2164308923) {
v_src_bytes_per_pixel = 8;
}
v_n = (((uint64_t)(io2_a_src - iop_a_src)) / ((uint64_t)(v_src_bytes_per_pixel)));
v_n = wuffs_base__u64__min(v_n, ((uint64_t)(((uint32_t)(self->private_impl.f_width - self->private_impl.f_dst_x)))));
v_j = v_n;
while (v_j >= 8) {
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 8)))) {
iop_a_src += (v_src_bytes_per_pixel * 8);
}
v_j -= 8;
}
while (v_j > 0) {
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 1)))) {
iop_a_src += (v_src_bytes_per_pixel * 1);
}
v_j -= 1;
}
} else {
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
&self->private_impl.f_swizzler,
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
wuffs_base__pixel_buffer__palette(a_dst),
&iop_a_src,
io2_a_src);
}
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
&self->private_impl.f_swizzler,
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
wuffs_base__pixel_buffer__palette(a_dst),
&iop_a_src,
io2_a_src);
if (v_n == 0) {
status = wuffs_base__make_status(wuffs_nie__note__internal_note_short_read);
goto ok;
@@ -40796,14 +40887,12 @@ wuffs_png__decoder__do_decode_image_config(
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
goto ok;
}
label__1__continue:;
while (true) {
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
if (a_src && a_src->meta.closed) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
goto label__1__continue;
}
self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32)));
@@ -41479,20 +41568,22 @@ wuffs_png__decoder__decode_other_chunk(
self->private_impl.f_seen_srgb = true;
}
} else if (self->private_impl.f_chunk_type == 1397641844) {
if (self->private_impl.f_seen_trns || (self->private_impl.f_color_type > 3) || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
if (self->private_impl.f_seen_trns || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
status = wuffs_png__decoder__decode_trns(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
} else if (self->private_impl.f_color_type > 3) {
} else {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
status = wuffs_png__decoder__decode_trns(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
}
self->private_impl.f_seen_trns = true;
}
@@ -43202,13 +43293,10 @@ wuffs_png__decoder__skip_frame(
self->private_impl.f_chunk_type_array[3] = 0;
label__0__continue:;
while (true) {
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
if (a_src && a_src->meta.closed) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
goto label__0__continue;
}
self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32)));
@@ -43447,14 +43535,12 @@ wuffs_png__decoder__do_decode_frame(
goto suspend;
}
}
label__0__continue:;
while (true) {
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
if (a_src && a_src->meta.closed) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
goto label__0__continue;
}
self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32)));
@@ -43589,14 +43675,12 @@ wuffs_png__decoder__do_decode_frame(
wuffs_png__decoder__filter_and_swizzle(self, a_dst, wuffs_base__slice_u8__subslice_j(a_workbuf, self->private_impl.f_workbuf_wi));
}
if (v_status.repr == wuffs_base__suspension__short_read) {
while (true) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
}
status = wuffs_base__make_status(wuffs_png__error__truncated_input);
goto exit;
}
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
}
label__1__break:;
v_status = wuffs_png__decoder__filter_and_swizzle(self, a_dst, a_workbuf);
+441
View File
@@ -0,0 +1,441 @@
// Copyright 2023 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------
// manual-test-truncated-input tests that decoding truncated versions of
// well-formed files produces a "truncated input" error.
//
// It tests every M-byte prefix of a valid N-byte file, for every positive M
// that satisfies (M < 65536) or ((N - M) <= 1024). The truncation point is
// either within 64 KiB of the start or 1 KiB of the end. It does not test
// every potential M in between, as that would take O(N**2) time.
#include <dirent.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
// Wuffs ships as a "single file C library" or "header file library" as per
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
//
// To use that single file as a "foo.c"-like implementation, instead of a
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
// compiling it.
#define WUFFS_IMPLEMENTATION
// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when
// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs'
// functions have static storage.
//
// This can help the compiler ignore or discard unused code, which can produce
// faster compiles and smaller binaries. Other motivations are discussed in the
// "ALLOW STATIC IMPLEMENTATION" section of
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
#define WUFFS_CONFIG__STATIC_FUNCTIONS
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
// entire Wuffs standard library, implementing a variety of codecs and file
// formats. Without this macro definition, an optimizing compiler or linker may
// very well discard Wuffs code for unused codecs, but listing the Wuffs
// modules we use makes that process explicit. Preprocessing means that such
// code simply isn't compiled.
#define WUFFS_CONFIG__MODULES
#define WUFFS_CONFIG__MODULE__ADLER32
#define WUFFS_CONFIG__MODULE__BASE
#define WUFFS_CONFIG__MODULE__BMP
#define WUFFS_CONFIG__MODULE__BZIP2
#define WUFFS_CONFIG__MODULE__CRC32
#define WUFFS_CONFIG__MODULE__DEFLATE
#define WUFFS_CONFIG__MODULE__GIF
#define WUFFS_CONFIG__MODULE__GZIP
#define WUFFS_CONFIG__MODULE__LZW
#define WUFFS_CONFIG__MODULE__NIE
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__TGA
#define WUFFS_CONFIG__MODULE__WBMP
#define WUFFS_CONFIG__MODULE__ZLIB
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../release/c/wuffs-unsupported-snapshot.c"
// ----
#ifndef DST_BUFFER_ARRAY_SIZE
#define DST_BUFFER_ARRAY_SIZE (64 * 1024 * 1024)
#endif
#ifndef WORKBUF_ARRAY_SIZE
#define WORKBUF_ARRAY_SIZE (256 * 1024 * 1024)
#endif
uint8_t g_dst_buffer_array[DST_BUFFER_ARRAY_SIZE] = {0};
uint8_t g_workbuf_array[WORKBUF_ARRAY_SIZE] = {0};
static int g_num_files_processed;
static struct {
char buf[PATH_MAX];
size_t len;
} g_relative_cwd;
// ----
static const char skipped[] = "skipped";
static const char unsupported_file_format[] = "unsupported file format";
static const char* //
handle_image_decoder(wuffs_base__io_buffer src,
int32_t fourcc,
bool full_decode) {
wuffs_base__image_decoder::unique_ptr dec(nullptr, &free);
switch (fourcc) {
case WUFFS_BASE__FOURCC__BMP:
dec = wuffs_bmp__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__GIF:
dec = wuffs_gif__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__NIE:
dec = wuffs_nie__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__PNG:
dec = wuffs_png__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__TGA:
dec = wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__WBMP:
dec = wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();
break;
default:
return unsupported_file_format;
}
if (!full_decode) {
while (true) {
auto dfc_status = dec->decode_frame_config(nullptr, &src);
if (dfc_status.is_ok()) {
// No-op.
} else if (dfc_status.repr == wuffs_base__note__end_of_data) {
break;
} else {
return dfc_status.message();
}
}
return nullptr;
}
wuffs_base__pixel_config pixcfg = {0};
pixcfg.set(WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL,
WUFFS_BASE__PIXEL_SUBSAMPLING__NONE, 0, 0);
wuffs_base__pixel_buffer pixbuf = {0};
auto sfs_status =
pixbuf.set_from_slice(&pixcfg, wuffs_base__make_slice_u8(nullptr, 0));
if (!sfs_status.is_ok()) {
return sfs_status.message();
}
while (true) {
auto df_status = dec->decode_frame(
&pixbuf, &src, WUFFS_BASE__PIXEL_BLEND__SRC,
wuffs_base__make_slice_u8(g_workbuf_array, WORKBUF_ARRAY_SIZE),
nullptr);
if (df_status.is_ok()) {
// No-op.
} else if (df_status.repr == wuffs_base__note__end_of_data) {
break;
} else {
return df_status.message();
}
}
if (src.meta.ri != src.meta.wi) {
return skipped;
}
return nullptr;
}
static const char* //
handle_io_transformer(wuffs_base__io_buffer src, int32_t fourcc) {
wuffs_base__io_transformer::unique_ptr dec(nullptr, &free);
switch (fourcc) {
case WUFFS_BASE__FOURCC__BZ2:
dec = wuffs_bzip2__decoder::alloc_as__wuffs_base__io_transformer();
break;
case WUFFS_BASE__FOURCC__GZ:
dec = wuffs_gzip__decoder::alloc_as__wuffs_base__io_transformer();
break;
case WUFFS_BASE__FOURCC__ZLIB:
dec = wuffs_zlib__decoder::alloc_as__wuffs_base__io_transformer();
break;
default:
return unsupported_file_format;
}
while (true) {
auto dst = wuffs_base__ptr_u8__writer(&g_dst_buffer_array[0],
DST_BUFFER_ARRAY_SIZE);
auto df_status = dec->transform_io(
&dst, &src,
wuffs_base__make_slice_u8(g_workbuf_array, WORKBUF_ARRAY_SIZE));
if (df_status.is_ok()) {
break;
} else if (df_status.repr == wuffs_base__suspension__short_write) {
// No-op.
} else {
return df_status.message();
}
}
return nullptr;
}
static const char* //
handle_various(wuffs_base__io_buffer src, int32_t fourcc) {
const char* status_msg;
status_msg = handle_image_decoder(src, fourcc, false);
if (status_msg != unsupported_file_format) {
if ((status_msg != nullptr) && !strstr(status_msg, "truncated input")) {
return status_msg;
}
return handle_image_decoder(src, fourcc, true);
}
status_msg = handle_io_transformer(src, fourcc);
if (status_msg != unsupported_file_format) {
return status_msg;
}
return unsupported_file_format;
}
static const char* //
handle_range(wuffs_base__io_buffer src,
int32_t fourcc,
size_t wi_min_incl,
size_t wi_max_excl) {
for (size_t wi = wi_min_incl; wi < wi_max_excl; wi++) {
src.meta.wi = wi;
const char* status_msg = handle_various(src, fourcc);
if ((status_msg != nullptr) && strstr(status_msg, "truncated input")) {
continue;
}
printf("when truncated to %zu bytes: ", wi);
if (status_msg) {
return status_msg;
}
return "have ok; want \"truncated input\"";
}
return nullptr;
}
static const char* //
handle(const uint8_t* ptr, size_t len) {
auto src = wuffs_base__ptr_u8__reader(const_cast<uint8_t*>(ptr), len, true);
int32_t fourcc = wuffs_base__magic_number_guess_fourcc(src.reader_slice(),
src.meta.closed);
if (fourcc <= 0) {
return skipped;
}
// Skip any invalid or unsupported input (when decoded in its entirety).
//
// Unsupported includes ignoring wuffs_base__note__i_o_redirect. We don't
// bother testing truncated PNGs-embedded-in-BMPs because we presumably
// already test truncated PNGs.
const char* status_msg = handle_various(src, fourcc);
if (status_msg) {
return skipped;
}
size_t file_len = src.meta.wi;
if (file_len <= (65536 + 1024)) {
return handle_range(src, fourcc, 1, file_len);
}
status_msg = handle_range(src, fourcc, 1, 65536);
if (status_msg) {
return status_msg;
}
return handle_range(src, fourcc, file_len - 1024, file_len);
}
// ----
static int //
visit(char* filename);
static int //
visit_dir(int fd) {
int cwd_fd = open(".", O_RDONLY, 0);
if (fchdir(fd)) {
printf("failed\n");
fprintf(stderr, "FAIL: fchdir: %s\n", strerror(errno));
return 1;
}
DIR* d = fdopendir(fd);
if (!d) {
printf("failed\n");
fprintf(stderr, "FAIL: fdopendir: %s\n", strerror(errno));
return 1;
}
printf("dir\n");
while (true) {
struct dirent* e = readdir(d);
if (!e) {
break;
}
if ((e->d_name[0] == '\x00') || (e->d_name[0] == '.')) {
continue;
}
int v = visit(e->d_name);
if (v) {
return v;
}
}
if (closedir(d)) {
fprintf(stderr, "FAIL: closedir: %s\n", strerror(errno));
return 1;
}
if (fchdir(cwd_fd)) {
fprintf(stderr, "FAIL: fchdir: %s\n", strerror(errno));
return 1;
}
if (close(cwd_fd)) {
fprintf(stderr, "FAIL: close: %s\n", strerror(errno));
return 1;
}
return 0;
}
static int //
visit_reg(int fd, off_t size) {
if ((size < 0) || (0x7FFFFFFF < size)) {
printf("failed\n");
fprintf(stderr, "FAIL: file size out of bounds");
return 1;
}
void* data = NULL;
if (size > 0) {
data = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
if (data == MAP_FAILED) {
printf("failed\n");
fprintf(stderr, "FAIL: mmap: %s\n", strerror(errno));
return 1;
}
}
const char* msg = handle((const uint8_t*)(data), size);
if (msg) {
printf("%s\n", msg);
} else {
printf("ok\n");
}
if ((size > 0) && munmap(data, size)) {
fprintf(stderr, "FAIL: mmap: %s\n", strerror(errno));
return 1;
}
if (close(fd)) {
fprintf(stderr, "FAIL: close: %s\n", strerror(errno));
return 1;
}
return (msg && (msg != skipped)) ? 1 : 0;
}
static int //
visit(char* filename) {
g_num_files_processed++;
if (!filename || (filename[0] == '\x00')) {
fprintf(stderr, "FAIL: invalid filename\n");
return 1;
}
int n = printf("- %s%s", g_relative_cwd.buf, filename);
printf("%*s", (60 > n) ? (60 - n) : 1, "");
fflush(stdout);
struct stat z;
int fd = open(filename, O_RDONLY, 0);
if (fd == -1) {
printf("failed\n");
fprintf(stderr, "FAIL: open: %s\n", strerror(errno));
return 1;
}
if (fstat(fd, &z)) {
printf("failed\n");
fprintf(stderr, "FAIL: fstat: %s\n", strerror(errno));
return 1;
}
if (S_ISREG(z.st_mode)) {
return visit_reg(fd, z.st_size);
} else if (!S_ISDIR(z.st_mode)) {
printf("skipped\n");
return 0;
}
size_t old_len = g_relative_cwd.len;
size_t filename_len = strlen(filename);
size_t new_len = old_len + strlen(filename);
bool slash = filename[filename_len - 1] != '/';
if (slash) {
new_len++;
}
if ((filename_len >= PATH_MAX) || (new_len >= PATH_MAX)) {
printf("failed\n");
fprintf(stderr, "FAIL: path is too long\n");
return 1;
}
memcpy(g_relative_cwd.buf + old_len, filename, filename_len);
if (slash) {
g_relative_cwd.buf[new_len - 1] = '/';
}
g_relative_cwd.buf[new_len] = '\x00';
g_relative_cwd.len = new_len;
int v = visit_dir(fd);
g_relative_cwd.buf[old_len] = '\x00';
g_relative_cwd.len = old_len;
return v;
}
int //
main(int argc, char** argv) {
g_num_files_processed = 0;
g_relative_cwd.len = 0;
for (int i = 1; i < argc; i++) {
int v = visit(argv[i]);
if (v) {
return v;
}
}
printf("PASS: %d files processed\n", g_num_files_processed);
return 0;
}
+4
View File
@@ -229,6 +229,10 @@ print_raw_passthrough(wuffs_base__io_buffer* src,
break;
}
uint64_t n1 = src->reader_length();
while (n1 == 0) {
TRY(read_buffer_from_file(src, f));
n1 = src->reader_length();
}
uint64_t n = wuffs_base__u64__min(n0, n1);
print_hex_dump(src->reader_pointer(), n);
src->meta.ri += n;
+1
View File
@@ -182,6 +182,7 @@ var u64TestCases = []uint64{
0x44B52D02C7E14AF6,
0x46293E5939A08CEA,
0x54B249AD2594C37D,
0x54B2987670ADB613,
0x7BBA44DF832B8D46,
0x7BF06B0BB1FB384C,
0x7C2485CE9E7A065F,
+72 -21
View File
@@ -50,7 +50,7 @@ pub struct decoder? implements base.image_decoder(
bitmap_info_len : base.u32,
padding : base.u32,
bits_per_pixel : base.u32,
bits_per_pixel : base.u32[..= 0xFFFF],
compression : base.u32,
// channel_etc's indexes are: B, G, R, A. This is in Wuffs' default order,
@@ -504,10 +504,12 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
var dst_bits_per_pixel : base.u32[..= 256]
var dst_bytes_per_pixel : base.u64[..= 32]
var dst_bytes_per_row : base.u64
var src_bytes_per_pixel : base.u32[..= 4]
var dst_palette : slice base.u8
var tab : table base.u8
var dst : slice base.u8
var i : base.u64
var j : base.u64
var n : base.u64
// TODO: the dst_pixfmt variable shouldn't be necessary. We should be able
@@ -552,14 +554,38 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
}
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
if i >= dst.length() {
// TODO: advance args.src if the dst pixel_buffer bounds is
// smaller than this BMP's image bounds?
continue.inner
if this.bits_per_pixel > 32 {
return "#unsupported BMP file"
}
src_bytes_per_pixel = this.bits_per_pixel / 8
if src_bytes_per_pixel == 0 {
return "#unsupported BMP file"
}
n = args.src.length() / (src_bytes_per_pixel as base.u64)
n = n.min(a: (this.width ~mod- this.dst_x) as base.u64)
j = n
while j >= 8 {
if args.src.length() >= ((src_bytes_per_pixel * 8) as base.u64) {
args.src.skip_u32_fast!(
actual: src_bytes_per_pixel * 8,
worst_case: src_bytes_per_pixel * 8)
}
j -= 8
} endwhile
while j > 0 {
if args.src.length() >= ((src_bytes_per_pixel * 1) as base.u64) {
args.src.skip_u32_fast!(
actual: src_bytes_per_pixel * 1,
worst_case: src_bytes_per_pixel * 1)
}
j -= 1
} endwhile
} else {
n = this.swizzler.swizzle_interleaved_from_reader!(
dst: dst[i ..],
dst_palette: dst_palette,
src: args.src)
}
n = this.swizzler.swizzle_interleaved_from_reader!(
dst: dst[i ..],
dst_palette: dst_palette,
src: args.src)
if n == 0 {
return "@internal note: short read"
}
@@ -943,15 +969,13 @@ pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_rea
}
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
if i >= dst.length() {
// TODO: advance args.src if the dst pixel_buffer bounds is
// smaller than this BMP's image bounds?
continue.inner
n = p0 as base.u64
} else {
n = this.swizzler.swizzle_interleaved_from_slice!(
dst: dst[i ..],
dst_palette: dst_palette,
src: this.scratch[.. 8 * p0])
}
n = this.swizzler.swizzle_interleaved_from_slice!(
dst: dst[i ..],
dst_palette: dst_palette,
src: this.scratch[.. 8 * p0])
if n == 0 {
return "@internal note: short read"
}
@@ -975,8 +999,9 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
var p0 : base.u32[..= 543]
var chunk_bits : base.u32
var chunk_count : base.u32
var chunk_bits : base.u32
var chunk_count : base.u32
var pixels_per_chunk : base.u32[..= 32]
// TODO: the dst_pixfmt variable shouldn't be necessary. We should be able
// to chain the two calls: "args.dst.pixel_format().bits_per_pixel()".
@@ -1005,8 +1030,34 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
}
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
if i >= dst.length() {
// TODO: advance args.src if the dst pixel_buffer bounds is
// smaller than this BMP's image bounds?
if this.bits_per_pixel == 1 {
chunk_count = ((this.width ~sat- this.dst_x) + 31) / 32
pixels_per_chunk = 32
} else if this.bits_per_pixel == 2 {
chunk_count = ((this.width ~sat- this.dst_x) + 15) / 16
pixels_per_chunk = 16
} else {
chunk_count = ((this.width ~sat- this.dst_x) + 7) / 8
pixels_per_chunk = 8
}
while (chunk_count >= 64) and (args.src.length() >= 256) {
args.src.skip_u32_fast!(actual: 256, worst_case: 256)
this.dst_x = this.width.min(a: this.dst_x ~mod+ (pixels_per_chunk * 64))
chunk_count -= 64
} endwhile
while (chunk_count >= 8) and (args.src.length() >= 32) {
args.src.skip_u32_fast!(actual: 32, worst_case: 32)
this.dst_x = this.width.min(a: this.dst_x ~mod+ (pixels_per_chunk * 8))
chunk_count -= 8
} endwhile
while chunk_count > 0 {
if args.src.length() < 4 {
return "@internal note: short read"
}
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
this.dst_x = this.width.min(a: this.dst_x ~mod+ (pixels_per_chunk * 1))
chunk_count -= 1
} endwhile
continue.loop
}
dst = dst[i ..]
@@ -1084,7 +1135,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
chunk_count -= 1
} endwhile
} else if this.bits_per_pixel == 4 {
} else {
// Calculate the remaining number of 32-bit chunks. At 4 bits per
// pixel there are 8 pixels per chunk. Division rounds up.
chunk_count = ((this.width ~sat- this.dst_x) + 7) / 8
+32 -7
View File
@@ -201,9 +201,11 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
var dst_bits_per_pixel : base.u32[..= 256]
var dst_bytes_per_pixel : base.u64[..= 32]
var dst_bytes_per_row : base.u64
var src_bytes_per_pixel : base.u32[..= 8]
var tab : table base.u8
var dst : slice base.u8
var i : base.u64
var j : base.u64
var n : base.u64
// TODO: the dst_pixfmt variable shouldn't be necessary. We should be able
@@ -232,14 +234,37 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
}
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
if i >= dst.length() {
// TODO: advance args.src if the dst pixel_buffer bounds is
// smaller than this NIE's image bounds?
continue
src_bytes_per_pixel = 4
assert src_bytes_per_pixel > 0
if this.pixfmt == base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE {
src_bytes_per_pixel = 8
assert src_bytes_per_pixel > 0
}
n = args.src.length() / (src_bytes_per_pixel as base.u64)
n = n.min(a: (this.width ~mod- this.dst_x) as base.u64)
j = n
while j >= 8 {
if args.src.length() >= ((src_bytes_per_pixel * 8) as base.u64) {
args.src.skip_u32_fast!(
actual: src_bytes_per_pixel * 8,
worst_case: src_bytes_per_pixel * 8)
}
j -= 8
} endwhile
while j > 0 {
if args.src.length() >= ((src_bytes_per_pixel * 1) as base.u64) {
args.src.skip_u32_fast!(
actual: src_bytes_per_pixel * 1,
worst_case: src_bytes_per_pixel * 1)
}
j -= 1
} endwhile
} else {
n = this.swizzler.swizzle_interleaved_from_reader!(
dst: dst[i ..],
dst_palette: args.dst.palette(),
src: args.src)
}
n = this.swizzler.swizzle_interleaved_from_reader!(
dst: dst[i ..],
dst_palette: args.dst.palette(),
src: args.src)
if n == 0 {
return "@internal note: short read"
}
+23 -29
View File
@@ -241,14 +241,10 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
// IDAT chunk breaks the loop. The only other possible critical chunk is a
// PLTE chunk. We verify PLTE checksums here but ignore other checksums.
while true {
while args.src.length() < 8,
post args.src.length() >= 8,
{
if args.src.is_closed() {
return "#bad chunk"
}
if args.src.length() < 8 {
yield? base."$short read"
} endwhile
continue
}
this.chunk_length = args.src.peek_u32be()
this.chunk_type = (args.src.peek_u64le() >> 32) as base.u32
@@ -619,11 +615,20 @@ pri func decoder.decode_other_chunk?(src: base.io_reader, framy: base.bool) {
}
} else if this.chunk_type == 'tRNS'le {
if this.seen_trns or (this.color_type > 3) or
if this.seen_trns or
((this.color_type == 3) and (not this.seen_plte)) {
return "#bad chunk"
} else if this.color_type > 3 {
// No-op, ignoring the chunk. The PNG spec section "11.3.2.1
// tRNS Transparency" says that "A tRNS chunk shall not appear
// for colour types 4 and 6, since a full alpha channel is
// already present in those cases." However, some real-world
// PNG images (incorrectly) have these. libpng treats this as a
// "benign error", not a fatal one. See
// https://github.com/google/wuffs/issues/146
} else {
this.decode_trns?(src: args.src)
}
this.decode_trns?(src: args.src)
this.seen_trns = true
}
}
@@ -1053,14 +1058,10 @@ pri func decoder.skip_frame?(src: base.io_reader) {
this.chunk_type_array[3] = 0
while true {
while args.src.length() < 8,
post args.src.length() >= 8,
{
if args.src.is_closed() {
return "#bad chunk"
}
if args.src.length() < 8 {
yield? base."$short read"
} endwhile
continue
}
this.chunk_length = args.src.peek_u32be()
this.chunk_type = (args.src.peek_u64le() >> 32) as base.u32
@@ -1141,14 +1142,10 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
}
while true {
while args.src.length() < 8,
post args.src.length() >= 8,
{
if args.src.is_closed() {
return "#bad chunk"
}
if args.src.length() < 8 {
yield? base."$short read"
} endwhile
continue
}
this.chunk_length = args.src.peek_u32be()
this.chunk_type = (args.src.peek_u64le() >> 32) as base.u32
@@ -1234,9 +1231,8 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
break
} else if status.is_error() or
((status == base."$short read") and args.src.is_closed()) {
// The input was truncated or invalid. Produce whatever
// pixels we can and then, if truncated, generate "$short
// read" forever.
// The input was invalid or truncated. Produce whatever
// pixels we can.
if this.workbuf_wi <= args.workbuf.length() {
// This might return "#internal error: inconsistent
// workbuf length" because of the ".. this.workbuf_wi".
@@ -1244,9 +1240,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
this.filter_and_swizzle!(dst: args.dst, workbuf: args.workbuf[.. this.workbuf_wi])
}
if status == base."$short read" {
while true {
yield? base."$short read"
} endwhile
return "#truncated input"
}
}
yield? status
+3
View File
@@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <limits.h>
#include <stdint.h>
#include "bzlib.h"
const char* //
+3
View File
@@ -23,6 +23,9 @@
// #define WUFFS_MIMICLIB_USE_LIBDEFLATE_INSTEAD_OF_ZLIB 1
// #define WUFFS_MIMICLIB_USE_MINIZ_INSTEAD_OF_ZLIB 1
#include <limits.h>
#include <stdint.h>
// -------------------------------- WUFFS_MIMICLIB_USE_XXX_INSTEAD_OF_ZLIB
#if defined(WUFFS_MIMICLIB_USE_LIBDEFLATE_INSTEAD_OF_ZLIB)
#include "libdeflate.h"
+3
View File
@@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <limits.h>
#include <stdint.h>
#include "gif_lib.h"
int //
+3
View File
@@ -24,6 +24,9 @@
// #define WUFFS_MIMICLIB_USE_LODEPNG_INSTEAD_OF_LIBPNG 1
// #define WUFFS_MIMICLIB_USE_STB_IMAGE_INSTEAD_OF_LIBPNG 1
#include <limits.h>
#include <stdint.h>
// -------------------------------- WUFFS_MIMICLIB_USE_XXX_INSTEAD_OF_LIBPNG
#if defined(WUFFS_MIMICLIB_USE_LIBSPNG_INSTEAD_OF_LIBPNG)
+14
View File
@@ -1026,6 +1026,7 @@ test_wuffs_strconv_parse_number_f64_regular() {
{.want = 0x46293E5939A08CEA, .str = "1e30"},
{.want = 0x54B249AD2594C37D, .str = "+1E+100"},
{.want = 0x54B249AD2594C37D, .str = "+_1_E_+_1_0_0_"},
{.want = 0x54B2987670ADB613, .str = "1.0168286519992372611942638e+100"},
{.want = 0x7BBA44DF832B8D46, .str = "1e+288"},
{.want = 0x7BF06B0BB1FB384C, .str = "1e+289"},
{.want = 0x7C2485CE9E7A065F, .str = "1e+290"},
@@ -1943,6 +1944,19 @@ test_wuffs_strconv_render_number_f64() {
"4.000",
.want_4g = "1e+100",
},
{
.x = 0x54B2987670ADB613,
.want__e = "1.0168286519992373e+100",
.want__f = "10168286519992373000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000"
"0",
.want_0g = "1e+100",
.want_2e = "1.02e+100",
.want_3f = "10168286519992372611942638135241625267907715220891"
"31363562982164291689352904657807934098133246961254"
"4.000",
.want_4g = "1.017e+100",
},
{
.x = 0x7BBA44DF832B8D46,
.want__e = "1e+288",
+7
View File
@@ -0,0 +1,7 @@
𝔸 U+1D538 MATHEMATICAL DOUBLE-STRUCK CAPITAL A. UTF-8: [F0 9D 94 B8].
This code point is outside of the Unicode BMP (Basic Multilingual Plane), but
its Unicode Category is Lu (Letter, uppercase), so it is still a valid file
path in terms of pkg.go.dev and its golang.org/x/mod/module package:
https://github.com/golang/mod/blob/dc121ce20ffab6bb810a0f231cfa9c24d3e51b29/module/module.go#L293
File renamed without changes.
-3
View File
@@ -1,3 +0,0 @@
😻 U+1F63B SMILING CAT FACE WITH HEART-SHAPED EYES. UTF-8: [F0 9F 98 BB].
This code point is outside of the Unicode BMP (Basic Multilingual Plane).