Shreyas220 commented on code in PR #676:
URL: https://github.com/apache/iceberg-go/pull/676#discussion_r2689776781


##########
puffin/puffin_reader.go:
##########
@@ -0,0 +1,387 @@
+// 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 puffin
+
+import (
+       "encoding/binary"
+       "encoding/json"
+       "errors"
+       "fmt"
+       "io"
+       "sort"
+)
+
+// PuffinReader
+//
+// Usage:
+//
+//     r, err := puffin.NewPuffinReader(file, fileSize)
+//     if err != nil {
+//         return err
+//     }
+//     footer, err := r.ReadFooter()
+//     if err != nil {
+//         return err
+//     }
+//     for i := range footer.Blobs {
+//         blob, err := r.ReadBlob(i)
+//         // process blob.Data
+//     }
+type PuffinReader struct {
+       r           io.ReaderAt
+       size        int64
+       footer      *Footer
+       footerStart int64 // cached after ReadFooter
+       maxBlobSize int64
+}
+
+// BlobData pairs a blob's metadata with its content.
+type BlobData struct {
+       Metadata BlobMetadata
+       Data     []byte
+}
+
+// ReaderOption configures a PuffinReader.
+type ReaderOption func(*PuffinReader)
+
+// WithMaxBlobSize sets the maximum blob size allowed when reading.
+// This prevents OOM attacks from malicious files with huge blob lengths.
+// Default is DefaultMaxBlobSize (256 MB).
+func WithMaxBlobSize(size int64) ReaderOption {
+       return func(r *PuffinReader) {
+               r.maxBlobSize = size
+       }
+}
+
+// NewPuffinReader creates a new Puffin reader.
+// It validates both the header and trailing magic bytes upfront.
+// The caller is responsible for closing the underlying io.ReaderAt.
+func NewPuffinReader(r io.ReaderAt, size int64, opts ...ReaderOption) 
(*PuffinReader, error) {
+       if r == nil {
+               return nil, errors.New("puffin: reader is nil")
+       }
+
+       // Minimum size: header magic + footer magic + footer trailer
+       // [Magic] + zero for blob + [Magic] + [FooterPayloadSize (assuming 
~0)] + [Flags] + [Magic]
+       minSize := int64(MagicSize + MagicSize + footerTrailerSize)

Review Comment:
   it is correct 
   footerTrailerSize. is `footer_length (4)+ flags (4) + magic (4)`



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to