Commit Graph
120 Commits
Author SHA1 Message Date
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
rykad 454f75cb22 core:encoding/base64: add support for url variant 2026-01-17 22:26:25 +00:00
StudebakerGuy fb479b3aae Corrected CRC's
CRC's were correct in relation to changes to address comments containing
-- at the end.
2026-01-08 11:34:50 -05:00
Zoltán Kéri d802a4e9fa encoding/base32: Fix padding validation for malformed input
Fix a bug where padding characters in the middle of input were
not detected when there was no trailing padding.

The "verify no padding in middle" check was inside `if
padding_count > 0`, so inputs like "MZ===YTBMZXW6YTB" would
incorrectly pass validation.

Test case added for this edge case.
2025-12-27 04:30:37 +01:00
Jeroen van Rijn 1fb95dade2 Expand base64 tests to include roundtrip 2025-11-22 15:44:19 +01:00
Jeroen van Rijn aec7d6480b Package lines for base32, move its tests to tests" 2025-10-09 15:27:53 +02:00
Laytan Laats 9eefa2006e encoding/cbor: support simd vectors 2025-06-04 22:00:02 +02:00
Laytan Laats 85224b21e6 encoding/cbor: support the matrix type 2025-06-04 21:51:12 +02:00
Jeroen van Rijn 062a3c2fae Fix parsing of CDATA tags (#5059)
Fixes #5054
2025-04-19 20:25:44 +02:00
jkenda 51b80c5a20 encoding/json: marshal enumerated arrays to objects with key-value pairs 2025-02-01 10:32:07 +01:00
gingerBill a300a860ec Add #+feature dynamic-literals to tests 2025-01-05 13:46:58 +00:00
Jeroen van Rijn 1a0a6c485d Add comment explaining #4515 test. 2024-11-25 13:47:04 +01:00
Jeroen van Rijn 2dc0187836 Test #4515 2024-11-25 13:16:27 +01:00
Laytan Laats 4608d26e6e encoding/cbor: fix skipping of ignored/missing fields in struct unmarshal 2024-10-26 22:39:46 +02:00
Laytan Laats 793ef6012b encoding/cbor: handle binary having more fields than the struct by discarding 2024-10-25 20:37:55 +02:00
Feoramund 1f04f541cf Fix -vet and -strict-style failures in tests 2024-08-26 16:20:08 -04:00
Laytan Laats 912f99abc8 encoding/cbor: various fixes
- "null" is the proper way to represent the nil value in the diagnostic
  format
- hex encoding in diagnostic format was wrong
- struct keys weren't sorted the right deterministic way
2024-08-09 21:56:54 +02:00
Jeroen van Rijn fc5ce30f34 Allow json to unmarshal empty struct. 2024-07-21 00:37:11 +02:00
Ronald e0a8bd04d5 Ensure deletion of maybe is delayed until we're finished with it. 2024-07-20 17:10:34 +01:00
Ronald f560b14d10 Fix typo in name of test 2024-07-20 17:10:19 +01:00
Ronald b584eeaade Add encoding/ini tests 2024-07-20 16:53:54 +01:00
VladPavliuk 3f8712edb0 Merge branch 'master' into json-add-int-key-map-support 2024-07-14 18:22:20 +03:00
gingerBill 8642d719f0 Imply #no_capture to all variadic parameters 2024-07-14 12:19:47 +01:00
gingerBill c7bd954752 Add more uses of #no_capture 2024-07-14 11:56:04 +01:00
VladPavliuk 76fe5d1346 Align ignore syntax of json tags with fmt, cbor 2024-07-14 00:21:05 +03:00
VladPavliuk 64ae99f016 Add support of ignore tag for json.marshal 2024-07-13 14:13:59 +03:00
VladPavliuk 79e2f63182 Small code refactoring in test_core_json 2024-07-13 00:38:58 +03:00
VladPavliuk 39983eaaa4 Remove unused imports in test_core_json 2024-07-13 00:26:54 +03:00
VladPavliuk dbdad0476d Allow to marshal and unmarshal maps with int keys 2024-07-13 00:07:48 +03:00