diff --git a/internal/abi/fastly/hostcalls_guest.go b/internal/abi/fastly/hostcalls_guest.go index f83e91f..9cf8a48 100644 --- a/internal/abi/fastly/hostcalls_guest.go +++ b/internal/abi/fastly/hostcalls_guest.go @@ -2487,12 +2487,13 @@ alloc: status := fastlyDictionaryGet( d.h, keyBuffer.Data, keyBuffer.Len, - prim.ToPointer(buf.Char8Pointer()), - buf.Cap(), + prim.ToPointer(buf.Char8Pointer()), buf.Cap(), prim.ToPointer(buf.NPointer()), ) - if status == FastlyStatusBufLen && buf.NValue() > 0 { - n = int(buf.NValue()) + // The Dictionary API cannot return the needed size with this error. + // Instead of perfectly adapting, we allocate the maximum length a value can have. + if status == FastlyStatusBufLen && n < dictionaryValueMaxLen { + n = dictionaryValueMaxLen goto alloc // goto saves having to allocate a function closure and avoids having to duplicate the hostcall } @@ -2521,8 +2522,7 @@ func (d *Dictionary) Has(key string) (bool, error) { if err := fastlyDictionaryGet( d.h, keyBuffer.Data, keyBuffer.Len, - prim.NullChar8Pointer(), - 0, + prim.NullChar8Pointer(), 0, prim.ToPointer(&npointer), ); err != FastlyStatusOK { if err == FastlyStatusBufLen { diff --git a/internal/abi/fastly/types.go b/internal/abi/fastly/types.go index db058c3..da414cc 100644 --- a/internal/abi/fastly/types.go +++ b/internal/abi/fastly/types.go @@ -185,8 +185,9 @@ func IsFastlyError(err error) (FastlyStatus, bool) { } const ( - ipBufLen = 16 // known size for IP address buffers - dnsBufLen = 256 // known size for "DNS" values, enough to hold the longest possible hostname or domain name + ipBufLen = 16 // known size for IP address buffers + dnsBufLen = 256 // known size for "DNS" values, enough to hold the longest possible hostname or domain name + dictionaryValueMaxLen = 8192 // known size for maximum config store value https://docs.fastly.com/en/guides/about-edge-dictionaries#limitations-and-considerations DefaultSmallBufLen = 128 // default size for "typically-small" values with variable sizes: HTTP methods, header names, tls protocol names, cipher suites DefaultMediumBufLen = 1024 // default size for values between small and large with variable sizes