Skip to content

ORA-22921: length of input buffer is smaller than amount requested #346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
simasmos opened this issue Jun 8, 2017 · 13 comments
Closed

ORA-22921: length of input buffer is smaller than amount requested #346

simasmos opened this issue Jun 8, 2017 · 13 comments
Assignees
Labels
Milestone

Comments

@simasmos
Copy link

simasmos commented Jun 8, 2017

When running ut.run() on a separate schema with lots of data, it eventually fails with the following error:

Error starting at line : 1 in command -
begin
ut.run();
end;
Error report -
ORA-22921: length of input buffer is smaller than amount requested
ORA-06512: на  "UT3.UT_RUNNER", line 87
ORA-06512: на  "UT3.UT_RUNNER", line 111
ORA-06512: на  "UT3.UT", line 292
ORA-06512: на  "UT3.UT", line 267
ORA-06512: на  line 2

There are no tests in the code. Trying ut.run() at the schema it's installed on works fine.
Here is dbms_output:

ORA-06512: на  "SYS.DBMS_LOB", line 1146
ORA-06512: на  "UT3.UT_UTILS", line 327
ORA-06512: на  "UT3.UT_METADATA", line 125
ORA-06512: на  "UT3.UT_ANNOTATIONS", line 348
ORA-06512: на  "UT3.UT_SUITE_MANAGER", line 77
ORA-06512: на  "UT3.UT_SUITE_MANAGER", line 288
ORA-06512: на  "UT3.UT_SUITE_MANAGER", line 342
ORA-06512: на  "UT3.UT_SUITE_MANAGER", line 503
ORA-06512: на  "UT3.UT_RUNNER", line 76

As far as I tested it, append_to_clob works alright and gets past some packages in the schema, then suddenly fails with a_src_clob size of 3212 and a_new_data of 75.
I'm not sure if it parses the packages alphabetically, but when I added a test package farther down the schema it failed at a different place.

@simasmos
Copy link
Author

simasmos commented Jun 8, 2017

Does it store anything in the memory or disc while looking through the code? Can limited space be the cause?

@jgebal
Copy link
Member

jgebal commented Jun 8, 2017

Can you provide the database nls settings, in particular the NLS_CHARACTERSET?

@jgebal
Copy link
Member

jgebal commented Jun 8, 2017

I can't seem to get to the root cause of the issue.
I was expecting it's related to the special characters present in your package.
If you're able to narrow-down the issue to the that is causing the issue?

@jgebal
Copy link
Member

jgebal commented Jun 8, 2017

Here is what I've tried:

SQL> set echo on
SQL> alter session set NLS_LANGUAGE=RUSSIAN                                   ;

Session altered.

SQL> alter session set NLS_TERRITORY=RUSSIA                                   ;

Session altered.

SQL> alter session set NLS_ISO_CURRENCY=RUSSIA                                ;

Session altered.

SQL> alter session set NLS_CALENDAR=GREGORIAN                                 ;

Session altered.

SQL> alter session set NLS_COMP=BINARY                                        ;

Session altered.

SQL> alter session set NLS_LENGTH_SEMANTICS=BYTE                              ;

Session altered.

SQL> alter session set NLS_NCHAR_CONV_EXCP=FALSE                              ;

Session altered.

SQL> 
SQL> declare
  2    l_source clob;
  3    l_str varchar2(4000);
  4  begin
  5     l_str := 'a regular line';
  6     ut_utils.append_to_clob(l_source, l_str );
  7     l_str := 'उदेश जिम्मे अंतर्गत संस्थान पुर्व मानव असरकारक';
  8     ut_utils.append_to_clob(l_source, l_str );
  9  end;
 10  /

PL/SQL procedure successfully completed.

SQL> 
SQL> select * from nls_database_parameters where parameter like '%CHARACTERSET%';

PARAMETER                                                                                                                        VALUE                                                           
-------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------
NLS_NCHAR_CHARACTERSET                                                                                                           AL16UTF16                                                       
NLS_CHARACTERSET                                                                                                                 AL32UTF8                                                        

@jgebal
Copy link
Member

jgebal commented Jun 8, 2017

Two more things that come to my mind are to try to change the way we create temporary lob:
In ut_utils (line 325) try to change:

        dbms_lob.createtemporary(a_src_clob, true);

to:

        dbms_lob.createtemporary(a_src_clob, false);

another thing to try could be change to:

        dbms_lob.createtemporary(a_src_clob, true, dbms_lob.call);

We could see how this works.

@jgebal
Copy link
Member

jgebal commented Jun 8, 2017

If any of the above solves it, we've learned something new ;)

@jgebal
Copy link
Member

jgebal commented Jun 8, 2017

@Pazus,
Have you any insight into the issue?
Do you know what can be the root cause?
Is it a bug in our code?

@jgebal jgebal added this to the v3.0.1 milestone Jun 8, 2017
@Pazus
Copy link
Member

Pazus commented Jun 9, 2017

Don't know yet...

@simasmos
Copy link
Author

simasmos commented Jun 9, 2017

Thanks everyone, the reason is found.
It was failing at the same 154th lob, and apparently there were wrong symbols in the comments section. Like ‘PE’ instead of 'PE' and – instead of -

DB Charset is same as yours:
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_CHARACTERSET AL32UTF8
After fixing the symbols tests are working as expected.

Thanks for your time again, great job on the project.

@jgebal
Copy link
Member

jgebal commented Jun 9, 2017

I think the code should still work OK.
Unfortunately I still cannot reproduce the issue :(
The below code works fine (on Oracle 12.1)

create or replace procedure tst_chars as
  l_source clob;
  l_str varchar2(4000);
begin
   l_str := 'a regular line';
   ut_utils.append_to_clob(l_source, l_str );
   l_str := 'उदेश जिम्मे अंतर्गत संस्थान पुर्व मानव असरकारक';
   ut_utils.append_to_clob(l_source, l_str );
   l_str := q'[Like ‘PE’ instead of 'PE' and – instead of -]';
   ut_utils.append_to_clob(l_source, l_str );
end;
/

set echo on
alter session set NLS_LANGUAGE=RUSSIAN     ;
alter session set NLS_TERRITORY=RUSSIA     ;
alter session set NLS_ISO_CURRENCY=RUSSIA  ;
alter session set NLS_CALENDAR=GREGORIAN   ;
alter session set NLS_COMP=BINARY          ;
alter session set NLS_LENGTH_SEMANTICS=BYTE;
alter session set NLS_NCHAR_CONV_EXCP=FALSE;

begin
  tst_chars;
end;
/

@simasmos
Copy link
Author

simasmos commented Jun 9, 2017

It failed on the following string:
a_new_data.txt

While the actual size is 71, length returned 75.

@jgebal
Copy link
Member

jgebal commented Jun 9, 2017

Got it reproduced:

create or replace package tst_chars as
--                 2) Status of the process = ‘PE’ with no linked data
end;
/
declare
  l_lines   sys.dbms_preprocessor.source_lines_t;
begin
  l_lines := sys.dbms_preprocessor.get_post_processed_source(
    object_type => 'PACKAGE',
    schema_name => user,
    object_name => 'TST_CHARS'
  );
  for i in 1..l_lines.count loop
    dbms_output.put_line(' dbms_lob.getlength='||dbms_lob.getlength(l_lines(i)));
    dbms_output.put_line(' length='||length(l_lines(i)));
    dbms_output.put_line(' lengthc='||lengthc(l_lines(i)));
    dbms_output.put_line(' length2='||length2(l_lines(i)));
    dbms_output.put_line(' length4='||length2(l_lines(i)));
    dbms_output.put_line(' lengthb='||lengthb(l_lines(i)));
    dbms_output.put_line('line='||l_lines(i));
  end loop;
end;
/

When I use my default NLS parameters in SQL Developer it gives:

 dbms_lob.getlength=71
 length=75
 lengthc=75
 length2=75
 length4=75
 lengthb=75
line=--                 2) Status of the process = ‘PE’ with no linked data

So we need to use dbms_lob.getlength on varchar2 to get the proper length - interesting.

When I change the NLS parameters to use russian it gives different results (and it actually makes the error not reproducable).

 dbms_lob.getlength=71
 length=71
 lengthc=71
 length2=71
 length4=71
 lengthb=75
line=--                 2) Status of the process = ‘PE’ with no linked data

Funny.

@jgebal jgebal added the bug label Jun 9, 2017
@jgebal
Copy link
Member

jgebal commented Jun 9, 2017

I'll try to create a unit test for it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants