jason810496 commented on code in PR #67315: URL: https://github.com/apache/airflow/pull/67315#discussion_r3296222934
########## go-sdk/pkg/execution/frames.go: ########## @@ -0,0 +1,257 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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. + +package execution + +import ( + "bytes" + "encoding/binary" + "fmt" + "io" + + "github.com/vmihailenco/msgpack/v5" +) + +// maxFrameSize caps the payload length a single frame may declare. A +// malformed length prefix from a corrupted stream (or hostile peer) would +// otherwise let readFrame allocate up to 4 GiB before the read failed. +// 64 MiB is far above any legitimate StartupDetails or XCom payload while +// still preventing accidental OOM. +const maxFrameSize = 64 * 1024 * 1024 + +// IncomingFrame represents a decoded frame received from the comm socket. +type IncomingFrame struct { + ID int + Body map[string]any + Err map[string]any // non-nil only for response frames (3-element arrays) +} + +// encodeRequest encodes a request frame (2-element msgpack array: [id, body]). +func encodeRequest(id int, body map[string]any) ([]byte, error) { + var buf bytes.Buffer + enc := msgpack.NewEncoder(&buf) + enc.UseCompactInts(true) + + if err := enc.EncodeArrayLen(2); err != nil { + return nil, err + } + if err := enc.EncodeInt(int64(id)); err != nil { + return nil, err + } + if err := enc.Encode(body); err != nil { + return nil, err + } + return buf.Bytes(), nil +} + +// writeFrame writes a length-prefixed msgpack payload to the writer. +// Format: [4-byte big-endian length][payload bytes]. +// +// The prefix and payload are concatenated into a single buffer and written +// in one Write call so we never leave a half-framed message on the wire if +// an io.Writer implementation does a short write between the two halves. +func writeFrame(w io.Writer, payload []byte) error { + buf := make([]byte, 4+len(payload)) + binary.BigEndian.PutUint32(buf[:4], uint32(len(payload))) Review Comment: Fixed in https://github.com/apache/airflow/pull/67315/changes/417786c06c820fffae39195e8455cb9f941b8950, respect the threshold with same size as Python side. ########## go-sdk/pkg/execution/frames.go: ########## @@ -0,0 +1,257 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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. + +package execution + +import ( + "bytes" + "encoding/binary" + "fmt" + "io" + + "github.com/vmihailenco/msgpack/v5" +) + +// maxFrameSize caps the payload length a single frame may declare. A +// malformed length prefix from a corrupted stream (or hostile peer) would +// otherwise let readFrame allocate up to 4 GiB before the read failed. +// 64 MiB is far above any legitimate StartupDetails or XCom payload while +// still preventing accidental OOM. +const maxFrameSize = 64 * 1024 * 1024 Review Comment: Fixed in https://github.com/apache/airflow/commit/417786c06c820fffae39195e8455cb9f941b8950, respect the threshold with same size as Python side. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
