[SERVER-13980] Interactive shell truncates line input longer than 4096 bytes Created: 18/May/14  Updated: 11/Nov/20  Resolved: 11/Nov/20

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: 4.9.0

Type: Bug Priority: Minor - P4
Reporter: Ernie Hershey Assignee: Kevin Pulo
Resolution: Done Votes: 3
Labels: move-sa, polish
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Backwards Compatibility: Minor Change
Operating System: ALL
Steps To Reproduce:

mongo --nodb < statement.js

Participants:
Case:

 Description   

As reported on IRC, the data in this array is weird somehow. This statement in the mongo shell returns an error:

var ar = [ [ [ -42.48063, -20.2949 ], [ -42.465657, -20.308542 ], [ -42.46568, -20.308727 ], [ -42.465772, -20.309284 ], [ -42.466087, -20.310824 ], [ -42.466588, -20.31333 ], [ -42.466849, -20.314861 ], [ -42.467151, -20.316337 ], [ -42.467343, -20.316769 ], [ -42.467752, -20.316544 ], [ -42.467752, -20.316544 ], [ -42.468346, -20.316247 ], [ -42.468051, -20.315601 ], [ -42.46772, -20.31464 ], [ -42.467498, -20.31356 ], [ -42.467532, -20.31321 ], [ -42.467494, -20.312928 ], [ -42.467412, -20.312619 ], [ -42.467302, -20.312399 ], [ -42.467089, -20.312276 ], [ -42.466883, -20.312084 ], [ -42.466729, -20.311785 ], [ -42.466704, -20.311459 ], [ -42.466807, -20.311146 ], [ -42.467055, -20.310419 ], [ -42.467196, -20.310223 ], [ -42.467316, -20.310072 ], [ -42.467336, -20.309828 ], [ -42.467134, -20.309303 ], [ -42.466883, -20.308754 ], [ -42.466849, -20.308658 ], [ -42.466842, -20.308421 ], [ -42.466859, -20.307858 ], [ -42.467036, -20.307085 ], [ -42.46717, -20.306861 ], [ -42.467548, -20.306087 ], [ -42.467706, -20.305519 ], [ -42.468326, -20.304317 ], [ -42.468503, -20.303841 ], [ -42.468603, -20.303467 ], [ -42.468714, -20.302869 ], [ -42.468803, -20.302734 ], [ -42.468919, -20.302678 ], [ -42.469394, -20.302616 ], [ -42.469845, -20.302537 ], [ -42.470581, -20.302358 ], [ -42.471177, -20.302156 ], [ -42.471779, -20.301859 ], [ -42.472052, -20.301618 ], [ -42.472363, -20.301444 ], [ -42.472731, -20.301332 ], [ -42.473294, -20.301169 ], [ -42.474314, -20.300967 ], [ -42.474905, -20.300782 ], [ -42.475401, -20.300672 ], [ -42.475849, -20.300556 ], [ -42.475978, -20.300486 ], [ -42.476093, -20.300449 ], [ -42.477183, -20.300148 ], [ -42.477493, -20.300093 ], [ -42.477744, -20.300039 ], [ -42.477856, -20.300011 ], [ -42.478036, -20.30001 ], [ -42.478087, -20.300001 ], [ -42.478115, -20.299996 ], [ -42.478089, -20.299893 ], [ -42.478014, -20.299667 ], [ -42.478002, -20.299635 ], [ -42.477983, -20.29953 ], [ -42.477979, -20.299507 ], [ -42.477981, -20.299408 ], [ -42.477993, -20.299335 ], [ -42.478013, -20.29926 ], [ -42.478032, -20.299197 ], [ -42.478045, -20.299136 ], [ -42.478048, -20.299111 ], [ -42.478053, -20.299095 ], [ -42.478063, -20.299082 ], [ -42.478079, -20.299073 ], [ -42.478095, -20.299072 ], [ -42.478112, -20.299076 ], [ -42.478127, -20.299086 ], [ -42.478134, -20.299101 ], [ -42.478309, -20.299092 ], [ -42.478471, -20.299091 ], [ -42.478585, -20.299109 ], [ -42.478701, -20.299128 ], [ -42.479161, -20.299261 ], [ -42.479241, -20.299106 ], [ -42.479304, -20.299004 ], [ -42.479399, -20.298895 ], [ -42.479504, -20.29879 ], [ -42.479609, -20.298697 ], [ -42.479743, -20.298598 ], [ -42.479823, -20.298563 ], [ -42.479787, -20.298273 ], [ -42.479794, -20.297985 ], [ -42.479802, -20.297937 ], [ -42.479813, -20.297885 ], [ -42.479832, -20.297836 ], [ -42.479855, -20.297786 ], [ -42.47992, -20.297691 ], [ -42.479992, -20.297599 ], [ -42.480072, -20.297507 ], [ -42.480113, -20.297467 ], [ -42.48025, -20.297354 ], [ -42.480589, -20.297087 ], [ -42.480672, -20.297008 ], [ -42.48079, -20.296888 ], [ -42.48087, -20.296796 ], [ -42.480939, -20.296705 ], [ -42.480969, -20.296659 ], [ -42.481026, -20.296571 ], [ -42.481087, -20.29647 ], [ -42.48111, -20.296418 ], [ -42.481125, -20.296366 ], [ -42.481128, -20.296347 ], [ -42.481132, -20.296315 ], [ -42.481128, -20.296265 ], [ -42.481116, -20.296196 ], [ -42.481106, -20.29617 ], [ -42.481079, -20.296128 ], [ -42.481048, -20.296092 ], [ -42.48098, -20.296033 ], [ -42.480949, -20.296008 ], [ -42.480877, -20.295966 ], [ -42.480839, -20.295951 ], [ -42.480721, -20.295894 ], [ -42.480675, -20.295867 ], [ -42.480629, -20.295837 ], [ -42.480583, -20.295804 ], [ -42.480507, -20.295728 ], [ -42.480472, -20.29569 ], [ -42.480427, -20.295642 ], [ -42.480395, -20.295607 ], [ -42.480352, -20.29556 ], [ -42.480318, -20.295432 ], [ -42.480324, -20.295364 ], [ -42.480342, -20.295268 ], [ -42.480397, -20.295124 ], [ -42.480482, -20.29499 ], [ -42.48063, -20.2949 ] ], [ [ -42.480404, -20.295841 ], [ -42.480299, -20.295942 ], [ -42.480045, -20.295674 ], [ -42.480149, -20.29557 ], [ -42.480404, -20.295841 ] ] ];

But this statement executes fine. The only difference is changing negative numbers to positive:

var ar = [ [ [ 42.48063, 20.2949 ], [ 42.465657, 20.308542 ], [ 42.46568, 20.308727 ], [ 42.465772, 20.309284 ], [ 42.466087, 20.310824 ], [ 42.466588, 20.31333 ], [ 42.466849, 20.314861 ], [ 42.467151, 20.316337 ], [ 42.467343, 20.316769 ], [ 42.467752, 20.316544 ], [ 42.467752, 20.316544 ], [ 42.468346, 20.316247 ], [ 42.468051, 20.315601 ], [ 42.46772, 20.31464 ], [ 42.467498, 20.31356 ], [ 42.467532, 20.31321 ], [ 42.467494, 20.312928 ], [ 42.467412, 20.312619 ], [ 42.467302, 20.312399 ], [ 42.467089, 20.312276 ], [ 42.466883, 20.312084 ], [ 42.466729, 20.311785 ], [ 42.466704, 20.311459 ], [ 42.466807, 20.311146 ], [ 42.467055, 20.310419 ], [ 42.467196, 20.310223 ], [ 42.467316, 20.310072 ], [ 42.467336, 20.309828 ], [ 42.467134, 20.309303 ], [ 42.466883, 20.308754 ], [ 42.466849, 20.308658 ], [ 42.466842, 20.308421 ], [ 42.466859, 20.307858 ], [ 42.467036, 20.307085 ], [ 42.46717, 20.306861 ], [ 42.467548, 20.306087 ], [ 42.467706, 20.305519 ], [ 42.468326, 20.304317 ], [ 42.468503, 20.303841 ], [ 42.468603, 20.303467 ], [ 42.468714, 20.302869 ], [ 42.468803, 20.302734 ], [ 42.468919, 20.302678 ], [ 42.469394, 20.302616 ], [ 42.469845, 20.302537 ], [ 42.470581, 20.302358 ], [ 42.471177, 20.302156 ], [ 42.471779, 20.301859 ], [ 42.472052, 20.301618 ], [ 42.472363, 20.301444 ], [ 42.472731, 20.301332 ], [ 42.473294, 20.301169 ], [ 42.474314, 20.300967 ], [ 42.474905, 20.300782 ], [ 42.475401, 20.300672 ], [ 42.475849, 20.300556 ], [ 42.475978, 20.300486 ], [ 42.476093, 20.300449 ], [ 42.477183, 20.300148 ], [ 42.477493, 20.300093 ], [ 42.477744, 20.300039 ], [ 42.477856, 20.300011 ], [ 42.478036, 20.30001 ], [ 42.478087, 20.300001 ], [ 42.478115, 20.299996 ], [ 42.478089, 20.299893 ], [ 42.478014, 20.299667 ], [ 42.478002, 20.299635 ], [ 42.477983, 20.29953 ], [ 42.477979, 20.299507 ], [ 42.477981, 20.299408 ], [ 42.477993, 20.299335 ], [ 42.478013, 20.29926 ], [ 42.478032, 20.299197 ], [ 42.478045, 20.299136 ], [ 42.478048, 20.299111 ], [ 42.478053, 20.299095 ], [ 42.478063, 20.299082 ], [ 42.478079, 20.299073 ], [ 42.478095, 20.299072 ], [ 42.478112, 20.299076 ], [ 42.478127, 20.299086 ], [ 42.478134, 20.299101 ], [ 42.478309, 20.299092 ], [ 42.478471, 20.299091 ], [ 42.478585, 20.299109 ], [ 42.478701, 20.299128 ], [ 42.479161, 20.299261 ], [ 42.479241, 20.299106 ], [ 42.479304, 20.299004 ], [ 42.479399, 20.298895 ], [ 42.479504, 20.29879 ], [ 42.479609, 20.298697 ], [ 42.479743, 20.298598 ], [ 42.479823, 20.298563 ], [ 42.479787, 20.298273 ], [ 42.479794, 20.297985 ], [ 42.479802, 20.297937 ], [ 42.479813, 20.297885 ], [ 42.479832, 20.297836 ], [ 42.479855, 20.297786 ], [ 42.47992, 20.297691 ], [ 42.479992, 20.297599 ], [ 42.480072, 20.297507 ], [ 42.480113, 20.297467 ], [ 42.48025, 20.297354 ], [ 42.480589, 20.297087 ], [ 42.480672, 20.297008 ], [ 42.48079, 20.296888 ], [ 42.48087, 20.296796 ], [ 42.480939, 20.296705 ], [ 42.480969, 20.296659 ], [ 42.481026, 20.296571 ], [ 42.481087, 20.29647 ], [ 42.48111, 20.296418 ], [ 42.481125, 20.296366 ], [ 42.481128, 20.296347 ], [ 42.481132, 20.296315 ], [ 42.481128, 20.296265 ], [ 42.481116, 20.296196 ], [ 42.481106, 20.29617 ], [ 42.481079, 20.296128 ], [ 42.481048, 20.296092 ], [ 42.48098, 20.296033 ], [ 42.480949, 20.296008 ], [ 42.480877, 20.295966 ], [ 42.480839, 20.295951 ], [ 42.480721, 20.295894 ], [ 42.480675, 20.295867 ], [ 42.480629, 20.295837 ], [ 42.480583, 20.295804 ], [ 42.480507, 20.295728 ], [ 42.480472, 20.29569 ], [ 42.480427, 20.295642 ], [ 42.480395, 20.295607 ], [ 42.480352, 20.29556 ], [ 42.480318, 20.295432 ], [ 42.480324, 20.295364 ], [ 42.480342, 20.295268 ], [ 42.480397, 20.295124 ], [ 42.480482, 20.29499 ], [ 42.48063, 20.2949 ] ], [ [ 42.480404, 20.295841 ], [ 42.480299, 20.295942 ], [ 42.480045, 20.295674 ], [ 42.480149, 20.29557 ], [ 42.480404, 20.295841 ] ] ];



 Comments   
Comment by Kevin Pulo [ 11/Nov/20 ]

This change only applies to the legacy mongo shell. For many purposes, the new mongosh shell (currently in beta) is better suited for interactive and scripting work with MongoDB.

When the legacy mongo shell reads an input line from stdin with more than 4095 characters, it will now output the message:

WARNING: input line truncated at 4095 bytes.

The line will continue to be parsed and executed, as before, despite the truncation (usually, but not always, resulting in a failure). As before, the 4096-th byte and onwards will then be read and processed, possibly resulting in further failures or unexpected results (or further occurrences of the warning message, if the line is over 8190 bytes).

This applies to lines read interactively, and when input is piped in such as

mongo < some_script.js
program_that_outputs_shell_commands | mongo

It does not apply to lines read via

mongo some_script.js

It also applies when the mongo shell reads lines from the ~/.dbshell history file (which should only be longer than 4095 bytes if the history file has been edited or written by something other than the mongo shell), though in that case the message reads

WARNING: some history file lines were truncated at 4095 bytes.

Comment by Githook User [ 11/Nov/20 ]

Author:

{'name': 'Kevin Pulo', 'email': 'kevin.pulo@mongodb.com', 'username': 'devkev'}

Message: SERVER-13980 warn when shell input lines are truncated
Branch: master
https://github.com/mongodb/mongo/commit/c575750f73b7a490a60919777dc49c45ec4f2e0c

Comment by J Rassi [ 18/May/14 ]

In interactive mode, the shell consumes 4096 bytes of input at a time; your first example statement is 4108 bytes long. Updating title of this ticket to "Interactive shell truncates line input longer than 4096 bytes".

This issue was introduced as part of SERVER-2792, and affects all versions of the shell since 1.9.0.

Generated at Thu Feb 08 03:33:29 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.