148 Commits
Author SHA1 Message Date
bplu4t2f 9b399220f5 Merge branch 'master' into simplify-strings-io-fmt-strconv-interactions 2026-10-27 15:49:41 +01:00
gingerBill aa342487d0 core:encoding/json: Check object keys as strictly as string values as strictly as string values 2026-10-27 11:54:18 +00:00
gingerBill 2b547b522f Fuzz array counts with keys that is_valid does not check 2026-10-27 11:28:35 +00:00
gingerBill 47a10c3529 core:encoding/json: Use parse_integer for Values; out-of-range ones wrap 2026-10-27 09:51:07 +00:00
gingerBill 589e597d7a core:encoding/json: Scan digit runs eight bytes at a time 2026-10-27 09:24:53 +00:00
gingerBill 203f6e90b2 Fuzz array element counts on lexical corner cases against the reference 2026-10-27 08:54:20 +00:00
gingerBill 0efe9e3b73 Test that the tokenizer's string verdict matches is_valid_string_literal 2026-10-26 23:01:18 +00:00
gingerBill 22ea4c548d core:encoding/json: Marshal floats as the shortest text that round-trips 2026-10-26 22:47:20 +00:00
gingerBill 5154731afc Skip exact JSON harness comparisons on input with an empty object key 2026-10-26 22:25:23 +00:00
gingerBill 515f228b9f Fuzz .Allow_Duplicate_Fields; compare defaults where no object repeats a key 2026-10-26 22:11:28 +00:00
gingerBill 2dc61824dc Fuzz and benchmark .Reserve_Maps; ignore map capacity in the JSON harness 2026-10-26 21:21:58 +00:00
gingerBill be8fe3a42d Fuzz and benchmark .Skip_Validation against the frozen JSON reference 2026-10-26 20:49:22 +00:00
gingerBill 7c6c254b88 Benchmark long ASCII strings; compare only union tags after errors in harness 2026-10-26 20:24:30 +00:00
gingerBill 418255c193 Add differential fuzz harness and benchmark 2026-10-26 19:41:02 +00:00
Jeroen van Rijn 0786b7e4f6 Fix #8030
Fixes #8030
2026-10-25 18:08:48 +01:00
bplu4t2f 2a6352c38d Merge branch 'master' into simplify-strings-io-fmt-strconv-interactions 2026-10-25 17:43:57 +01:00
bplu4t2f 1ad267f1ad encoding/base64: Malformed Quantum error case is distinct from Invalid Padding. 2026-10-24 13:31:04 +02:00
bplu4t2f a20304f5d5 encoding/base64: Analyze input more closely before starting to decode
Refactors the code slightly so that a `decode_analyze` step is performed
first. This is needed because the previous architecture was a bit
broken and did not allow fixing certain edge cases with broken input.

Automatically fixes `writer_path_malformed_tails`,
`test_newline_rejected_lenient`,
and `lenient_ignore_excess_padding` edge cases.
2026-10-24 13:30:31 +02:00
bplu4t2f 2c2163f7f7 encoding/base64: Add tests to demonstrate holes in the current implementation. 2026-10-24 13:30:24 +02:00
bplu4t2f 22499d44c7 encoding/base64: Fix buggy test output 2026-10-24 12:56:19 +02:00
Jeroen van Rijn 8d94cbb450 core:encoding/endian: Add arbitrary-width (8..64 bit, multiple of 8) get/put procedures and tests
For when you need to get or put a "u24" as you might see in e.g. Bluetooth wire protocols.
2026-10-22 11:05:11 +02:00
bplu4t2f 9a16667c3e Add tests: JSON string marshaling edge cases 2026-10-16 14:20:08 +02:00
corleypc 3a840a0bd3 fix use after scope in core:encoding/json 2026-10-13 17:25:07 +03:00
bplu4t2f f5c9785d79 XML test: Log level to debug 2026-10-09 16:27:44 +02:00
bplu4t2f 18d3de890c XML hot path: Cleanup 2026-10-09 14:34:02 +02:00
bplu4t2f cde71cdfc0 XML hot path: Cleanup instrumentation 2026-10-09 14:18:27 +02:00
bplu4t2f 40b68a7102 Experimental hot path optimization in XML test. 2026-10-08 23:09:37 +02:00
gingerBill 711f08a641 Make is_type_lock_free follow what each target lowers without library calls, and reject atomics on types which are not lock-free 2026-10-07 21:58:32 +01:00
Arthur031221 eaa1cb34eb Fix CBOR bit set byte order conversion 2026-10-02 18:57:49 +08:00
Arthur031221 f01284d372 [core:encoding/csv] Read the final multiline record before EOF
The multiline line reader returned EOF with buffered data, so record
parsing discarded the last row when the file had no trailing newline.
Clear EOF while data remains, as the normal line reader does.

Add regressions for final records, empty input and unterminated quotes.
The normal core suite passes 627 tests with the new CSV tests included.
2026-10-02 14:10:58 +08:00
Ihor Antonov a5bef5224c core: add unpadded base64 encoding
core:encoding/base64 can only produce padded output, so callers that need
the canonical unpadded ("raw") form -- JOSE base64url, Go's
RawStdEncoding/RawURLEncoding -- have to encode and then trim, which
forces an extra allocation and cleanup dance around the returned string.

Add an Encode_Options bit set, mirroring Decode_Options, and honor
{.No_Padding} in `encode`, `encode_into_buf`, `encode_into`, and
`encoded_len`. Existing calls and padded output are unchanged.

Tests cover the RFC 4648 section 9 illustrations and section 10 test
vectors across the standard and URL alphabets, padded and raw, plus Go's
reference corpus. Newline characters are asserted to be rejected per
RFC 4648 section 3.3. Comments in `encode_impl` document the 24-bit group
packing and the padding decision for partial groups.
2026-09-30 19:53:10 -07:00
Ihor Antonov 2109ba8fbd core: add strict base64 decoding
core:encoding/base64 currently decodes leniently: it infers padding from the
last one or two bytes, accepts missing/extra/interior padding, and does not
check the trailing padding bits required by RFC 4648 Section 3.5.
Go exposes canonical decoding as `Encoding.Strict()`; Odin has no equivalent,
so downstream ports (e.g. age) have to reimplement base64 from scratch.

This adds opt-in strict decoding through a `Decode_Options` bit set.
Existing calls and behavior are unchanged.
2026-09-28 19:59:23 -07:00
Jack Mordaunt 641844dae7 core/encoding/json: size the unquote buffer for replaced invalid UTF-8
unquote_string replaces each byte that is not valid UTF-8 with U+FFFD,
which is three bytes for one, but sized its buffer as len(s) + 2*UTF_MAX:
slack for a single replacement, not for one per invalid byte. A string
holding several ran the write cursor past the end, an out-of-range slice
under bounds checking and a memory-safety bug without it.

Count the invalid bytes in the remainder up front and size for them. The
escape sequences never grow their input, so they need no allowance.
2026-09-25 14:27:40 -03:00
user.name 6ccde7f80b bugfix: core/encoding/json leaks the key and value of a malformed object
parse_object_body allocates an object key, then may fail in parse_colon or
parse_value before that key is ever inserted into the object. Its cleanup defer
only walks `obj`, so a key that never got there is unreachable to it. The caller
cannot free it either -- a failed parse returns a nil Value -- so it leaks.

The same applies to the parsed element on the duplicate-key path, and to both on
the out-of-memory path.

JSON5 makes this reachable from ordinary malformed input, because an unquoted
ident is a legal key and anything other than a colon after it fails. Plain JSON
leaks it too, via a quoted key.

before, measured with a tracking allocator over 8 inputs x 2 specs:

	LEAK JSON5  colon fails after unquoted key   1 alloc / 7 bytes
	LEAK JSON   colon fails after quoted key     1 alloc / 2 bytes
	LEAK JSON5  colon fails after quoted key     1 alloc / 2 bytes
	LEAK JSON   value fails after key            1 alloc / 2 bytes
	LEAK JSON5  value fails after key            1 alloc / 2 bytes
	LEAK JSON   nested value fails               2 alloc / 4 bytes
	LEAK JSON5  nested value fails               2 alloc / 4 bytes
	LEAK JSON   deep nesting fails               3 alloc / 6 bytes
	LEAK JSON5  deep nesting fails               3 alloc / 6 bytes
	LEAK JSON   array element fails              1 alloc / 2 bytes
	LEAK JSON5  array element fails              1 alloc / 2 bytes
	total leaked allocations: 17

after, same probe:

	total leaked allocations: 0

The leak scales with nesting depth -- one orphaned key per enclosing object -- so
a service parsing untrusted JSON leaks a little on every malformed request.

The fix marks the key and the element as owned by the loop iteration until they
are stored, and frees them otherwise. The duplicate-key path loses its explicit
delete, which the same mechanism now covers.

Found via odinfmt, which reported a 7-byte leak in a downstream test that parses
`{ broken not json` to check that invalid input is rejected.

Regression test added to tests/core/encoding/json: it reports
`17 leaks and 0 bad frees` without this change and passes with it. The existing
11 tests pass unchanged under -define:ODIN_TEST_FAIL_ON_BAD_MEMORY=true.
2026-08-31 11:39:42 -07:00
mo 4e0a71c24c Add non-allocating hex.decode_into_buffer
Also minor fixes to documentation of hex.decode().

Adds tests of the new procedure with buffers the correct size, larger,
and too small.
2026-08-16 19:48:19 +12:00
kalsprite 2fd11467c8 Merge branch 'master' into x.508 2026-07-12 10:51:44 -07:00
Jeroen van Rijn 4b9f396cb3 Fix whitespace normalize 2026-06-30 13:23:44 +02:00
kalsprite 4876cf03bf asn1 DER reader/writer and X.509 reader 2026-06-13 23:40:08 -07:00
Yawning Angel e7698e4adf core/encoding/pem: Initial import 2026-06-02 17:48:46 +09:00
Yawning Angel 82a18797b4 core/encoding/base64: Misc fixes and improvements
- Add error checking to `decode`
- Add `encode_into_buf`/`decode_into_buf`
2026-05-26 00:38:50 +09:00
andzdroid f123fb1e91 encoding/cbor: fix order-dependent partial unmarshals 2026-03-15 13:20:57 +00:00
Jeroen van Rijn 98b65f2c2e Update unicode generator + test 2026-02-21 01:54:17 +01:00
Jeroen van Rijn e7dbabf668 core:os -> core:os/old && core:os/os2 -> core:os 2026-02-09 15:50:21 +01:00
Jeroen van Rijn af57035fd6 tests/core/io -> os2 2026-02-08 12:50:23 +01:00
Jeroen van Rijn f63c209478 Convert core:encoding/hxa 2026-02-08 12:42:26 +01:00
Jeroen van Rijn 1cbd60f40e Reenable core:encoding/ini tests 2026-02-08 12:42:25 +01:00
Jeroen van Rijn 4acdd3f60b Fix CRC 2026-01-22 11:49:47 +01:00
Jeroen van Rijn 3f8a32aeb9 Merge branch 'master' into xmlcomment 2026-01-22 11:47:23 +01:00
Jeroen van Rijn 27ac0ebc37 Merge pull request #6145 from odin-lang/bill/html-escape
Update `core:encoding/entity`
2026-01-18 13:37:45 +01:00
gingerBill ca507d0596 Fix crc32 for xml_test_entities_unbox_decode 2026-01-18 12:30:55 +00:00