Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2019-05

ContentData field size in FCGI_ContentRecord of fastcgi unit

6 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Zamrony P. Juhara
From fastcgi.pp

https://github.com/graemeg/freepascal/blob/master/packages/fastcgi/src/fastcgi.pp

In line 510
FCGI_ContentRecord = record
    header : FCGI_Header;
    ContentData : array[0..1023] of byte;
end;
Field ContentData is 1024 bytes. Actual ContentData length is related to field ContentLength of FCGI_Header. ContentLength is declared as word type to conform with FastCGI specification. So maximum ContentLength is 65536 bytes.

According  to FastCGI specification,

http://www.mit.edu/~yandros/doc/specs/fcgi-spec.html "contentData: Between 0 and 65535 bytes of data, interpreted according to the record type."

Why fastcgi.pp declared it as array[0..1023] of byte instead of array[0.. 65535] of byte ?

Reply by email

Michael Van Canneyt
to Zamrony P. Juhara
Zamrony P. Juhara wrote 17 lines
> From fastcgi.pp https://github.com/graemeg/freepascal/blob/master/packages/fastcgi/src/fastcgi.pp In line 510 FCGI_ContentRecord = record     header : FCGI_Header;     ContentData : array[0..1023] of byte; end; Field ContentData is 1024 bytes. Actual ContentData length is related to field ContentLength of FCGI_Header. ContentLength is declared as word type to conform with FastCGI specification. So maximum ContentLength is 65536 bytes. According  to FastCGI specification, http://www.mit.edu/~yandros/doc/specs/fcgi-spec.html "contentData: Between 0 and 65535 bytes of data, interpreted according to the record type." Why fastcgi.pp declared it as array[0..1023] of byte instead of array[0.. 65535] of byte ?

This unit is a translation of a library. Most likely, that was exactly the value specified in the original header files.

I would not recommend using this unit.
It is most likely outdated, and I would not even know what library it supports. I will ask on the core group what to do, I think it is better to remove it.

Free Pascal supports fastcgi natively using the custfcgi or fpfcgi units.

Michael.

Reply by email

Zamrony P. Juhara
to Michael Van Canneyt

custfcgi.pp and fpfcgi.pp both directly /indirectly depends on fastcgi unit.

Zamrony P. Juhara

On Sat, May 18, 2019 at 16:54, Michael Van Canneyt wrote:

Zamrony P. Juhara wrote 17 lines
> From fastcgi.pp https://github.com/graemeg/freepascal/blob/master/packages/fastcgi/src/fastcgi.pp In line 510 FCGI_ContentRecord = record     header : FCGI_Header;     ContentData : array[0..1023] of byte; end; Field ContentData is 1024 bytes. Actual ContentData length is related to field ContentLength of FCGI_Header. ContentLength is declared as word type to conform with FastCGI specification. So maximum ContentLength is 65536 bytes. According  to FastCGI specification, http://www.mit.edu/~yandros/doc/specs/fcgi-spec.html "contentData: Between 0 and 65535 bytes of data, interpreted according to the record type." Why fastcgi.pp declared it as array[0..1023] of byte instead of array[0.. 65535] of byte ?

This unit is a translation of a library. Most likely, that was exactly the value specified in the original header files.

I would not recommend using this unit.
It is most likely outdated, and I would not even know what library it supports. I will ask on the core group what to do, I think it is better to remove it.

Free Pascal supports fastcgi natively using the custfcgi or fpfcgi units.

Michael.

Reply by email

Zamrony P. Juhara
to Michael Van Canneyt

I do not think so, because custfpcgi.pp is using many const and types declared in fastcgi.pp. removing it will cause rewrite in many parts of custfcgi units Zamrony P. Juhara

On Sat, May 18, 2019 at 17:36, Michael Van Canneyt wrote:

Zamrony P. Juhara wrote
custfcgi.pp and fpfcgi.pp both directly /indirectly depends on fastcgi unit.

AFAIK this dependency can be removed, if it exists.

Michael.

Reply by email

Michael Van Canneyt
to Zamrony P. Juhara
Zamrony P. Juhara wrote
I do not think so, because custfpcgi.pp is using many const and types declared in fastcgi.pp. removing it will cause rewrite in many parts of custfcgi units

You are right.

I should not try to answer questions based on memory alone :(

I did some digging and here is the long explanation:

The record definition is a formal record definition. The buffer was defined as 1024 bytes (1K), but this is completely arbitrary. It could have been [0..0], or [0..MaxInt].
Probably [0..0] would have been better.
I will change it to that.

In practice a FCGI_ContentRecord is never used. A PFCGI_ContentRecord (pointer to) is used to typecast an array of byte and extract the necessary header fields from the array.

It's a little like the typinfo structures: they describe memory layouts, but some structures are just formal, for example

TVmtFieldTable =   record
         Count: Word;
         ClassTab: PVmtFieldClassTab;
         { should be array[Word] of TFieldInfo;  but
           Elements have variant size! force at least proper alignment }
         Fields: array[0..0] of TVmtFieldEntry;
       end;

The FCGI_ContentRecord definition should be seen in the same light: a formal definition.

Michael.

Reply by email