Skip to content

Commit 2bdbfd1

Browse files
committed
bugfix increase plugin max input size
Also fix parse error display to stderr.
1 parent c995a58 commit 2bdbfd1

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

plugin/src/Main.purs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import Data.UInt64 as UInt64
2727
import Effect (Effect)
2828
import Effect.Aff (runAff_, throwError, error)
2929
import Effect.Class (liftEffect)
30-
import Effect.Console as Console
30+
import Effect.Class.Console as Console
3131
import Google.Protobuf.Compiler.Plugin (CodeGeneratorRequest(..), CodeGeneratorResponse, CodeGeneratorResponse_File(..), mkCodeGeneratorResponse, parseCodeGeneratorRequest, putCodeGeneratorResponse)
3232
import Google.Protobuf.Descriptor (DescriptorProto(..), EnumDescriptorProto(..), EnumValueDescriptorProto(..), FieldDescriptorProto(..), FieldDescriptorProto_Label(..), FieldDescriptorProto_Type(..), FieldOptions(..), FileDescriptorProto(..), OneofDescriptorProto(..), SourceCodeInfo(..), SourceCodeInfo_Location(..))
3333
import Node.Buffer (Buffer, toArrayBuffer, fromArrayBuffer)
@@ -45,7 +45,7 @@ main = runAff_ (either (unsafeCoerce >>> Console.error) (\_ -> pure unit)) do
4545
-- Protoc just assumes that when it writes the request, we get the whole
4646
-- request on our read of stdin. Protoc doesn't tell us how to determine
4747
-- that we have read the whole request.
48-
-- So we read and parse in a loop until we have enough bytes that the
48+
-- So we read chunks and parse in a loop until we have enough bytes that the
4949
-- parse succeeds.
5050
flip tailRecM [] \bs -> do
5151
{buffers:b,readagain} <- readSome stdin
@@ -56,10 +56,17 @@ main = runAff_ (either (unsafeCoerce >>> Console.error) (\_ -> pure unit)) do
5656
if not readagain then do
5757
void $ throwError $ error "stdin is not readable."
5858
pure (Done unit)
59-
else if (Array.length bs') < 20 then do
59+
else if (Array.length bs') < 10000 then do
60+
-- What we want to do here is detect whether this parsing error was
61+
-- because we read to the end of the buffer and need to read more.
62+
-- But we don't have a good way to do that right now, so we assume
63+
-- that we need to read more, unless we have already read 10000 chunks.
64+
-- (Chunk size is usually 65536 bytes.)
65+
-- If the parsing error happened for some other reason then we should
66+
-- error out here.
6067
pure (Loop bs')
6168
else do
62-
void $ throwError $ error $ unsafeCoerce err
69+
void $ throwError $ error $ show err
6370
pure (Done unit)
6471
Right request -> do
6572
responseBuf <- execPutM $ putCodeGeneratorResponse (generate request)

0 commit comments

Comments
 (0)