497 Commits
Author SHA1 Message Date
bplu4t2f 1489279f20 encoding/json: Simplify format_float with Float_Flags. 2026-10-27 17:48:27 +01:00
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 92a99b0f18 core:encoding/json: Skip and copy validated string values without rescanning 2026-10-27 11:28:28 +00:00
gingerBill fee4c80d4c core:encoding/json: Fix array count for keys that end at a newline 2026-10-27 11:28:18 +00:00
gingerBill a2a97fd384 core:encoding/json: Dispatch common tokens on one byte switch in get_token 2026-10-27 10:33:07 +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 89884834ac core:encoding/json: Count elements of validated arrays without the tokenizer 2026-10-27 08:54:11 +00:00
gingerBill 54f4dff6e3 core:encoding/json: Check each string once by reusing the tokenizer's verdict 2026-10-26 23:01:06 +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 5f349bae69 core:encoding/json: Match an empty key only to a field tagged json:"" 2026-10-26 22:25:05 +00:00
gingerBill 918b39d836 core:encoding/json: Error on duplicate struct fields; resolve names lazily 2026-10-26 22:11:18 +00:00
gingerBill a157887c3e core:encoding/json: Drop temporary key/scalar allocations; add .Reserve_Maps 2026-10-26 21:21:46 +00:00
gingerBill cb934fd53f core:encoding/json: Add Unmarshal_Flags with .Skip_Validation 2026-10-26 20:49:13 +00:00
gingerBill 5d6edc58e4 core:encoding/json: Drop bounds-check blocks that showed no measurable gain 2026-10-26 20:24:18 +00:00
gingerBill 439099e922 core:encoding/json: Scan plain string runs 8 bytes at a time and validate inline 2026-10-26 20:16:25 +00:00
gingerBill 2649e5d627 core:encoding/json: Scan tokens bytewise and skip values without building them 2026-10-26 20:01:11 +00:00
gingerBill 0570fafe1c core:encoding/json: Parse short decimal integers directly in unmarshal 2026-10-26 19:40:29 +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 b83cd571a8 encoding/base64: Lenient decode prioritizes Invalid_Padding over Invalid_Character.
Applies only if unexpected interior padding is the only problem in a quantum.

This is to be consistent with the error that would be returned by strict decode
in that case (-> `Invalid_Padding`).
2026-10-24 13:30:31 +02:00
bplu4t2f e0c71140d1 encoding/base64: Make decoded_len use the more accurate decode_analyze.
TMP fix cbor decoded_len
2026-10-24 13:30:31 +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
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 bdee042049 strconv.write_float can now take flags (just like the integer counterpart). Notably, this simplifies lots of usage code because '+' sign handling is no longer ultra awkward at the call site. Default value preserves existing behavior (prepend +). 2026-10-16 14:20:11 +02:00
bplu4t2f 51f72ec0da encoding/json: Implement marshaling JSON string values directly in this package, rather than hammering it into io. Rationale: Writing a JSON string value is an entirely different operation compared to write_quoted_string, and is specific to encoding/json. 2026-10-16 14:20:08 +02:00
bplu4t2f 4fa98fae77 encoding/json: Protect public marshaling APIs against misuse - Marshal_Options is also the mutable state object; was passed around by pointer, but never nil checked. 2026-10-15 16:55:37 +02:00
corleypc 3a840a0bd3 fix use after scope in core:encoding/json 2026-10-13 17:25:07 +03:00
bplu4t2f b17c76e5a4 !!WIP!! Merge branch 'master' into speedup-ci - missing tests/issues/run.bat and run.sh changes 2026-10-09 20:56:04 +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 94ea51a5d1 XML hot path: Use an arena instead of strings_to_free. 2026-10-09 14:00:56 +02:00
bplu4t2f f1673a3140 Disable instrumentation for measurement (also when is awkward here :( bill what were you thinking) 2026-10-09 13:22:42 +02:00
bplu4t2f f25fc5b2a8 XML hot path: Instrumentation and some optimizations 2026-10-09 13:11:08 +02:00
Jeroen van Rijn 1ee37f38a1 Merge branch 'master' into fix-7763 2026-10-08 10:06:44 -07:00
bplu4t2f ea224d0f7e Fix #7763: Fix base64 decoder edge case 2026-10-07 19:30:48 +02:00
gingerBill 9863858570 Fix the deterministic CBOR encoding of maps with non-string keys 2026-10-07 15:52:48 +01:00
Jeroen van Rijn c1ac93f9a6 `delete(dst, allocator) 2026-10-07 11:21:07 +02:00
bplu4t2f 758cdd19ae Fix #7779 - Make encoding/hex behave well on errors. 2026-10-07 10:47:57 +02: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
Ben Botwin 2796bf0fd0 removes private from unmarshal_value for use in user unmarshalers 2026-09-29 16:58:31 -04: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
kalsprite deeddc7b33 add missing endian 128 types 2026-08-25 23:03:11 -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